David Buckley David Buckley - 7 months ago 23
Vb.net Question

Change date format vb.net

I need to change a date format to the following format yyyyMMdd its for edi files but the below is not working its just leaving the orderDatedb as is in same format

Dim orderDateDb As DateTime = orderHeaderDt.Rows(0).Item("Orderdate")
orderDateDb = Format(orderDateDb, "yyyyMMdd")


this is the column in db

enter image description here

How can i convert this to prooper format in vb.net

Answer

Use the To String way...

ToString("yyyyMMdd")

You wanted a function, here it is...

 Public Class Form1

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'Example usage...

    Dim orderDateDb As String = ConvertDateTime(orderHeaderDt.Rows(0).Item("Orderdate"))
    MessageBox.Show(orderDateDb)

 End Sub

  Public Shared Function ConvertDateTime(ByVal dtDateTime As DateTime) As String
    Return dtDateTime.ToString("yyyyMMdd")
  End Function
 End Class
Comments