How to format date that is a string value??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have date in a string format like string strDate = "110204".
Now i want to convert this string to MM/dd/yyyy format. How do i do this????
I used string.Format(strDate, "MM/dd/yyyy") but no effect. I guess i have to
convert this to date and than to string(MM/dd/yyyy). Please help.
Thanks in advance.
faktujaa
 
faktujaa,
What does 110204 represent?

February 4th of 2011?
April 2nd of 2011?
November 2nd of 2004?
February 11th of 2004?

Something else?


In either case I would use DateTime.ParseExact to convert the string to a
DateTime, then use DateTime.ToString to convert it to the specific format.

Something like:

Const format As String = "MMddyy"
Dim input As String = "110204"
Dim value As DateTime = DateTime.ParseExact(input, format, Nothing)
Dim output As String = value.ToString("MM/dd/yyyy")

You can rearrange the format constant to the proper order the input string
is in.

Hope this helps
Jay
 
Back
Top