Reputation: 8188
How can I convert a date in the string format CCYYMMDD (i.e. 20120624) to MM/DD/YYYY (i.e. 06/24/2012)?
I am trying this but its not parsing, throwing an exception jDate is not a valid datetime format
Public Shared Function ConvertJDateToDate(ByVal jDate As String) As String
Dim d As Date = Date.ParseExact("yyyyMMdd", jDate, CultureInfo.InvariantCulture)
Dim newText As String = d.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)
Return newText
End Function
Upvotes: 0
Views: 789
Reputation: 155418
Your arguments are in the wrong order.
You want this:
Dim d As Date = DateTime.ParseExact( jDate, "yyyyMMdd", CultureInfo.InvariantCulture )
Upvotes: 6