Tuesday, 20 August 2013

vb.NET (for ASPX page): Parse a string to a date

vb.NET (for ASPX page): Parse a string to a date

I'm trying to make this line work:
MyDateTime = DateTime.ParseExact("2/8/2013 11:59:00 AM", "yyyy-mm-dd
hh:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
I'm getting date/time strings from spreadsheets in the above format, and I
can't control that. There's a ton of help online, including this site,
about converting strings to dates, and I've tried them all, but I keep
getting this error :
"System.FormatException: String was not recognized as a valid DateTime."
I"m just about ready to write my own custom parser, but that doesn't seem
very elegant. Is there some built-in way to convert a string like mine
into the date/time format I need?
Thanks for any help.

No comments:

Post a Comment