Groups | Blog | Home
all groups > dotnet faqs > september 2004 >

dotnet faqs : convert a custom format string back to datetime


Lynn
9/18/2004 2:46:33 AM
Hi All,
We all know we can use
toString(strFormat) mothod to convert a datetime variable to a custom
string, let say strFormat = "YYYY!MM*DD", then we can get '2004!09*18', how
can I get convert the string back to datetime based on the specific format
'YYYY!MM*DD'.

Convert.todatetime method seems does not work.


Thanks a lot.


Lynn

Jonathan Allen
9/24/2004 10:47:42 PM
Dim d As Date = #9/18/2004#
Dim s As String
s = d.ToString("yyyy!MM*dd")
Console.WriteLine(s)
Dim d2 As Date
d2 = Date.ParseExact(s, "yyyy!MM*dd", New
System.Globalization.DateTimeFormatInfo)
Console.WriteLine(d2)

--
Jonathan Allen


[quoted text, click to view]

AddThis Social Bookmark Button