How to convert this date format "september 29, 2008 - 13:00:07 " into "9/29/2008 1:00:07 PM"?
Printable View
How to convert this date format "september 29, 2008 - 13:00:07 " into "9/29/2008 1:00:07 PM"?
To convert a string representation of a date into a Date object you call Date.ParseExact or, if there's a chance it might not be valid, Date.TryParseExact. To convert a Date object into a string in a specific format you call ToString and specify that format. MSDN describes all the standard and custom format strings available to you for converting between Strings and Dates in each direction. I'll leave it to you to look that up because it will benefit you to see all of what's available rather than just a single solution to a single problem. Once you've read that documentation you'll never have to ask for a date format again.
yep.. i started referring when this date format banged my head,,.Quote:
Originally Posted by jmcilhinney
but immediately i cant get the solution. so went through string manipultaion
anyway thanks jmc..
Well, as I said, MSDN describes all the custom format strings available so I don't know where you were looking. That original string is "MMMM d, yyyy - HH:mm:ss" and the final string is "M/dd/yyyy h:mm:ss tt". Simple.
@vijy - you read this http://msdn.microsoft.com/en-us/library/az4se3k1.aspx and did not find the answer????
Code:Dim ds As String = "september 29, 2008 - 13:00:07"
ds = ds.Replace("-"c, " "c)
Dim dt As DateTime
dt = DateTime.Parse(ds)
Debug.WriteLine(dt.ToString)