I have searched the forum for solutions like this, however I did not find one that actually matches my particular issue.
This might be in need of a more experienced eye in order to find the problem, so I appreciate all help!
Problem: I am trying to parse a string with a date to a DateTime variable. However, even if the string date format is exactly the same, it still throws an exception.
I would like to know why, and how I can solve it. I really can't see what is wrong there!
try
{
string value = "Sep-17-2012 03:04:07 am";
string format = "M-dd-yyyy hh:mm:ss tt";
DateTime temp = DateTime.ParseExact(value, format, CultureInfo.InvariantCulture);
}
catch(Exception e){}
Thanks in advance,
Mad
Your format should be MMM not M http://www.dotnetperls.com/datetime-format
string format = "MMM-dd-yyyy hh:mm:ss tt";
M - display one-digit month number
MMM - display a three letter month
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With