Solved

How to pass DateTime C#

Posted on 2009-05-20
6
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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