Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert DateTime error:

Posted on 2016-08-15
5
Medium Priority
?
75 Views
Last Modified: 2016-08-15
Hi,

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

Date Error
0
Comment
Question by:SmashAndGrab
  • 2
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41756248
can you try to set your value to 08/26/2016 ?
0
 
LVL 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 total points
ID: 41756255
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
 

Author Comment

by:SmashAndGrab
ID: 41756277
just tried this..


error
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41756310
since you sepcify MM, have you tried: 26/08/2016 ?
0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 41757199
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question