Converting date and time format to date
Hi All,
I have a problem. I'm making a alarm clock and I need a way of converting a "dd/MM/yyyy HH:mm:ss" format into a date time format. This means I'll be able to compare the dates in a listbox using the for each function, to the current date and see whever it has passed and therfore the alarm should be deleted. It is currently in a string form so I can't use < and > to compare it to the current date as that is in a date form. I've tried using CDate but it doesn't work as it only will convert these formats:
"August 12, 2004", "2:07:30 PM" and "August 12, 2004 2:07:30 PM"
Can anyone help?
Thanks,
m1la
Re: Converting date and time format to date
There's a few static members of the Date structure that can help your cause. Parse, TryParse, ParseExact, TryParseExact.
Code:
Dim MyDate As DateTime
If DateTime.TryParse("03/05/2010 11:23:21", MyDate) Then
'It worked
Debug.WriteLine(MyDate.ToString())
End If