Parsing DateTime

  • Thread starter Thread starter Snedker
  • Start date Start date
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
 
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
 
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
 
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/
 
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/
 
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
 
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
 
Back
Top