Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi,i know how to validate date as dd/mm/yyyy format in asp.net but now i want to validate date as dd/mm/yyyy format in window how can i do this please help
Posted

John Simmons gave you a good start, now add the IFormatProvider and the DateTimeStyles to the DateTime.TryParse method, or in the other hand, you can try to add 3 separate boxes, one for day, one more for month and the last one for year
 
Share this answer
 
Comments
Albin Abel 7-Mar-11 23:04pm    
Yes. He even don't want to search how to use tryparse. My 5
You could use DateTime.TryParse. If it returns true, the date is valid.
 
Share this answer
 
Comments
software_Engi08 7-Mar-11 16:14pm    
i have written code as DateTime dob;
//if (!DateTime.TryParse(maskedTextBox1.Text, out dob))
//{
// MessageBox.Show("invalid date");
//}
but this is mm/dd/yyyy format.i want dd/mm/yyyy format
Gonzoox 7-Mar-11 16:44pm    
this is a good start, +5
Albin Abel 7-Mar-11 23:02pm    
This is correct. My 5
i think try with masked text box it will helps you
try to validate with masked text box
 
Share this answer
 
Comments
software_Engi08 7-Mar-11 16:16pm    
i have used masktext box as mask=00/00/0000.but this is in mm/dd/yyyy format .i want dd/mm/yyyy format .please help
Albin Abel 7-Mar-11 23:03pm    
Masked Textbox won't validate date format
First of all, "mm" means minutes, "MM" means months! And now:
DateTime dt;
bool valid = DateTime.TryParseExact(text, "dd/MM/yyyy", null, DateTimeStyles.None, out dt);

This should do the job.
 
Share this answer
 
v2
Comments
Member 11428767 7-Feb-15 2:04am    
its not working with windows form
Hi
John is correct. It is your problem don't know how to use Tryparse

See that function accepts a format.
C#
DateTime dob;
DateTimeFormatInfo info = new DateTimeFormatInfo();
info.ShortDatePattern = "dd/MM/yyyy";
DateTime.TryParse("30/3/2011", info, DateTimeStyles.None, out dob);


This way it works. You are ready to search what tryparse doing, instead you are simply looking for ready answer. Better try something.
 
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