RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find YYYY-MM-DD[ HH:MM[:SS]]
Expression
^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-9])|(2[0-3]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])))?))?$
Description
Date YYYY-MM-DD (optional time HH:MM(optional seconds :SS)). Was borrowed from this [http://regexlib.com/REDetails.aspx?regexp_id=390] but changed to use 24 hour time and optional seconds. You can use / - or space for date delimiters, so 2004-12-31 works just as well as 2004/12/31. Checks leap year from 1901 to 2099.
Matches
2006-1-20 | 2006/01/20 | 2006-01-20 15:30 | 2006-01-20 15:30:21
Non-Matches
2003-2-29 | 2003-13-02 | 2003-2-2 10:72:30
Author Rating: Not yet rated. Brett ODonnell
Source http://regexlib.com/REDetails.aspx?regexp_id=390
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Small error regarding time hour 00
Name: Andreas H.
Date: 1/13/2009 1:24:32 PM
Comment:
You got an error within your regex: - "2009-02-20 01:02:03" -> matches - "2009-02-20 00:01:01" -> Does not match but this is valid! Reason: "(\s(((0?[1-9])|(1[0-9])|(2[0-3]))\:" should be replaced with "(\s(((0?[0-9])|(1[0-9])|(2[0-3]))\:" Everthing else seems to be fine :-), thanks for your work!


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials