Saturday, December 27, 2008

How to: Parse dates (ASP.NET 2.0)

In ASP.NET 1.x, you would need to warp a try/catch around the DateTime.Parse method to try and parse a string into a DateTime object.
In ASP.NET 2.0, you can use the DateTime.TryParse method to parse your date strings.

DateTime dt;

bool isSuccessful = DateTime.TryParse("05/28/2007",out dt);

If the TryParse was not successful, then it would return false. Also the DateTime returning from the output parameterwil be set to DateTime.MinValue.
Make sure you have the "out" keyword at the beginning of the second parameter, since this parmeter is an output parameter.

1 comment:

RIDHA said...

good work, if you want to get more experience in ASP.NET 2.0 i advise you to take a look at
http://khaskhoussy.blogspot.com
a chosen article and a proffissionals ebooks are available to download