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

x
?
Solved

How to pass DateTime C#

Posted on 2009-05-20
6
Medium Priority
?
263 Views
Last Modified: 2012-05-07
I have the following date 2009-05-19T00:00:00 i wish to pass to a date. But i'm getting

String was not recognized as a valid DateTime

string myDateString = "2009-05-19T00:00:00";

Date date = DateTime.Parse(myDateString);


0
Comment
Question by:frosty1
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 24431666
the T is probably throwing it of
0
 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24431723
The T is good there, it is the UTC format of a date, but it is missing the +HHMM for the offset to GMT.

Hmm, just tried, both the following lines works correctly for me:

// correct parsing of date strigns
DateTime dt1 = DateTime.Parse("2009-05-19T00:00:00+0100");
DateTime dt2 = DateTime.Parse("2009-05-19T00:00:00");

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24431732
PS: what type of object is your "Date" btw. In VB is exists, standard, but in C# it does not...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:frosty1
ID: 24431851
thanks abel,

Sorry i meant DateTime.

Turns out that i occasionally string myDateString was empty. Your clarification help me find this. Very helpful.
0
 
LVL 39

Expert Comment

by:abel
ID: 24431968
glad you found it. You can use TryParse if the string can be malformed. The return value is a boolean which you can use to report the error, instead of having a raised exception.
0
 

Author Comment

by:frosty1
ID: 24432155
hmm yeah, that would be alot neater. thanks again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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