Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
hi all ,
I have a date which i have stored as a string str = 2/31/2001 .. now i want to validate the date how can i do it .. i have used DateTime dt = Convert.ToDateTime(str); but it says that str is not a correct format ...
Posted

ASM
DateTime dt;
if (DateTime.TryParseExact(str, "M/d/yyyy", null, DateTimeStyles.None, out dt) == true)
{
//your date is valid and is in dt
}
 
Share this answer
 
Comments
iampradeepsharma 28-Sep-11 2:59am    
this worked thanks prerak..
Prerak Patel 28-Sep-11 3:10am    
You are welcome :)
sivac#programmer 20-Feb-16 11:31am    
This is help me a lot.Thanks.
Try DateTime.Parse(str);
 
Share this answer
 
if (DateTime.TryParseExact(str, "M/d/yyyy", null, DateTimeStyles.None, out dt) == true)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900