I have a firebird datebase, some tables have timestamp. For example, my database returns such dates: “1/4/2012 3:08:44 PM” or “12/20/2011 4:38:02 PM”. I use TryParseExact and code is as follows:
DateTime.TryParseExact(results[i][1], "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)
I tried many formats like “MM/dd/yyyy hh:mm:ss tt” but none of them worked. Please help me or I will go crazy this time…
Have a look at this article
http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx
The key part to look at is
So it may be that your database is not returning a standard pattern. Seems silly to me that this would throw an exception though. And in the example it is only saying a “date-only” value, which yours is not.
If you have the date in a string you could do the old manual fix-up: