Convert mm/dd/yyyy to yyyymmdd (VB.NET)

Viewed 95891

Is there any way I can convert a date of format: dd/mm/yyyy to yyyymmdd format? For example from : 25/07/2011 to 20110725? in VB.NET?

4 Answers
Public Function DateFormateYYYYMMDD(ByVal Dtp As DateTimePicker) As String

   Try
      Dim StrDate, StrYear, StrMonth, StrDay As String
      StrDate = FormatDateTime(Dtp.Value, DateFormat.ShortDate)
      StrMonth = Month(Dtp.Value)
      StrDay = Convert.ToString(Dtp.Value.Day)
      StrYear = Year(Dtp.Value)
      StrDate = StrYear + "-" + StrMonth + "-" + StrDay

      Return StrDate
   Catch ex As Exception

   End Try
End Function

this function can be used to convert datetime picker value format to yyyyMMdd

Related