• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 76
  • Last Modified:

Convert DateTime error:

Hi,

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

Date Error
0
SmashAndGrab
Asked:
SmashAndGrab
  • 2
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
can you try to set your value to 08/26/2016 ?
0
 
David Johnson, CD, MVPOwnerCommented:
Get rid of the ()'s or
DateTime myDate = DateTime.ParseExact("2009-05-08 14:40:52,531", "(DD-MM-YYYY HH:mm)",
                                       System.Globalization.CultureInfo.InvariantCulture)

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)
0
 
SmashAndGrabAuthor Commented:
just tried this..


error
0
 
Éric MoreauSenior .Net ConsultantCommented:
since you sepcify MM, have you tried: 26/08/2016 ?
0
 
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.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now