.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Convert String to DateTime using ASP.NET

Posted By:Gowthammanju       Posted Date: June 30, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This code explains about converting the string to datetime

here it is as

string sDate ="06/05/2010";
// this the regex to match the date ie: dd/MM/yyyy
string _dateExpression = @"^((0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](?:19|20)\d\d)$";
Regex chkDate = new Regex(_dateExpression);
if ((chkDate.IsMatch(sDate))
// so if the date is valid and its matched you can store the date on DB or do some manipulatio.
// show invalid date
catch (System.FormatException ex)
// show invalid date
catch(Exception ex1)
thats it!


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend