Water Posted January 5, 2004 Posted January 5, 2004 Hello! I looked in MSDN help but I couldn't understand how to convert String to DateTime. To be specific i have string "2003:10:31 22:34:52" and I need to convert it to DateTime object. How to do this? Please help. Best regards, Water Quote
Administrators PlausiblyDamp Posted January 5, 2004 Administrators Posted January 5, 2004 If the date parts were seperated by a character other than a : you could use DateTime.Parse Dim d As DateTime d = DateTime.Parse("2003/10/31 22:34:52") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Water Posted January 5, 2004 Author Posted January 5, 2004 Yes, but in my case date is not separated by "/". This is not problem, I will write some function to convert, but I ask for later purpose. Is it possible to say Format = "yyyy/dd/mm hh:ss" and to pass this to convert function? Quote
*Gurus* Derek Stone Posted January 5, 2004 *Gurus* Posted January 5, 2004 Dim dateTime As DateTime Dim dateTimeFormat() As String = {"yyyy/dd/MM hh:mm:ss", "yyyy/dd/MM h:m:s"} Dim dateTimeString As String = "2004/05/01 5:55:00" dateTime = dateTime.ParseExact(dateTimeString, dateTimeFormat, System.Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None) MessageBox.Show(dateTime.ToString("F"), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information) Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.