Parsing DateTime

S

Snedker

I have a string in the format "Tue May 26 09:16:40 2009". I need for
this to be saved to a DateTime.

I can easily write my own function to parse the date to a proper
DateTime format, but I would rather use common .NET functions. But can
it be done - and if so, what should i be using to get the job done?


Regards
Morten Snedker
 
S

Snedker

Did you try DateTime.Parse or DateTime.TryParse?

Reflecting on my question I can see it's a bit stupid. There's no of
parsing that expression without handling it first.

/Snedker
 
S

Snedker

Did you try DateTime.Parse or DateTime.TryParse?

Reflecting on my question I can see it's a bit stupid. There's no of
parsing that expression without handling it first.

/Snedker
 
J

Jonathan Wood

Yes I did. It throws a FormatException.

You asked for the .NET framework way of parsing that data, DateTime.Parse or
DateTime.TryParse is it. If someone enters a date in that format, then they
need to reenter using a different format.

If your task it to parse in exactly that format, then you'll need to parse
it manually.
Reflecting on my question I can see it's a bit stupid. There's no of
parsing that expression without handling it first.

Sorry, but I was unable to parse that statement.

Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
http://www.softcircuits.com/blog/
 
J

Jonathan Wood

Yes I did. It throws a FormatException.

You asked for the .NET framework way of parsing that data, DateTime.Parse or
DateTime.TryParse is it. If someone enters a date in that format, then they
need to reenter using a different format.

If your task it to parse in exactly that format, then you'll need to parse
it manually.
Reflecting on my question I can see it's a bit stupid. There's no of
parsing that expression without handling it first.

Sorry, but I was unable to parse that statement.

Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
http://www.softcircuits.com/blog/
 
S

Snedker

Use DateTime.ParseExact() or TryParseExact().  Those methods allow you to  
specify the exact format to be used.

Thanks to all of you for your time and effort!

Regards
Snedker
 
S

Snedker

Use DateTime.ParseExact() or TryParseExact().  Those methods allow you to  
specify the exact format to be used.

Thanks to all of you for your time and effort!

Regards
Snedker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top