Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.75/5 (3 votes)
Hi,

I would like to have a regular expression for the date time in the below formats
mm/dd/yyyy HH:MM:SS AM/PM
mm/dd/yyyy HH:MM AM/PM

Regards,
Vipul
Posted
Updated 14-Dec-10 22:07pm
v2
Comments
Sandeep Mewara 15-Dec-10 4:10am    
No effort.

Rather than re-invent the wheel, see http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5[^] which has similar expressions. Be warned though: they are complex, so if they don;t fit your need exactly, then you have a long job ahead. Get a copy of Expresso[^] it's free and can really help debug a regex!

I don't know what you are trying to achieve, but you may be better off using DateTime.ParseExact[^] instead...
 
Share this answer
 
^((((31\/(0?[13578]|1[02]))|((29|30)\/(0?[1,3-9]|1[0-2])))\/(1[6-9]|[2-9]\d)?\d{2})|(29\/0?2\/(((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|(0?[1-9]|1\d|2[0-8])\/((0?[1-9])|(1[0-2]))\/((1[6-9]|[2-9]\d)?\d{2})) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$


Hope this can help you.
 
Share this answer
 
Comments
komalpreet kaur 26-Mar-13 3:49am    
format shud be in mm/dd/yyyy hh:mm:ss... but it is in dd/mm/yyyy format

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