I'm using vb.net 2005.
How do convert this date / time 21/08/2008 00:21:00 to a DateTime object ?
I'm using vb.net 2005.
How do convert this date / time 21/08/2008 00:21:00 to a DateTime object ?
You can use a custom date time format string in conjuction with DateTime.ParseExact
or DateTime.TryParseExact
.
Dim dateTime as DateTime = _
DateTime.ParseExact("21/08/2008 00:21:00", "dd/MM/yyyy HH:mm:ss", _
CultureInfo.InvariantCulture)
Dim d as DateTime = DateTime.Parse("21/08/2008 00:21:00")
Console.WriteLine(d)
produces this:
21/08/2008 12:21:00 a.m.
If you want to be sure to parse that format correctly, you should use DateTime.ParseExact
with a custom format string matching your pattern (e.g. dd\/MM\/yyyy HH:mm:ss
).
I'm using vb.net not c#, my solutions a bit old, but it works
Dim d1 As Date
d1 = CDate("21/08/2008 00:21:00")
Console.WriteLine(d1)