Convert DateTime error:


I'm getting an error when trying to convert a datetime to a datetime.  I don't know why.

Date Error
Who is Participating?
David Johnson, CD, MVPConnect With a Mentor OwnerCommented:
Get rid of the ()'s or
DateTime myDate = DateTime.ParseExact("2009-05-08 14:40:52,531", "(DD-MM-YYYY HH:mm)",

IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
// Alternate choice: If the string has been input by an end user, you might
// want to format it according to the current culture:
// IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal)
Éric MoreauSenior .Net ConsultantCommented:
can you try to set your value to 08/26/2016 ?
SmashAndGrabAuthor Commented:
just tried this..

Éric MoreauSenior .Net ConsultantCommented:
since you sepcify MM, have you tried: 26/08/2016 ?
David Johnson, CD, MVPOwnerCommented:
you are going to have to do some work to get the string into something datetime can work with.. Months are 2 digits not 1 digit (they may also be 3 characters) I'd fix your input so that it returns 2 digits for the month or you have to do some string manipulation for months prior to October.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.