David Buckley David Buckley - 11 months ago 72
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


Use the To String way...


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"))

 End Sub

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