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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find dd/mm/yyyy hhMMss Julian to Gregorian DateTime
Expression
(?#Datetime for Julian and Gregorian Calenders Matchs dates from 0045 BC to 9999 A.D. Days and months are 1 or 2 digits Years are 4 digit with leading zeros if required. February is validate in all leap years Leap year rules for Julian and Gregorian calendars http://scienceworld.wolfram.com/astronomy/LeapYear.html Missing days for 1582 and 1752 are not matched. Though only one set should be applied to a calendar since they are caused by when the calendar was adopted Missing days http://scienceworld.wolfram.com/astronomy/GregorianCalendar.html Time can be either 12 or 24 hour format 12 hour format hh:MM:ss AM|PM minutes and seconds are optional 24 hour format hh:mm:ss seconds are optional, hours less than ten require leading zero Datetome format is a date, a space then a time. ) (?#Calandar from January 1st 45 B.C. to December 31, 1999 in dd/mm/yyyy format) (?! (?:(?:0?[5-9]|1[0-4])(?<sep>[-./])10\k<sep>(?:1582))| #Missing days from 1582 (?:(?:0?[3-9]|1[0-3])(?<sep>[-./])0?9\k<sep>(?:1752)) #or Missing days from 1752 (?# both sets of missing days such not be in the same calendar so remove one or the other) ) (?n:^(?=\d) # the character at the beginning a the sring must be a digit ( (?<day>31(?!.0?[2469]|11)|30(?!.0?2)| 29(?(.0?2)(?=.0?2.(?! #exclude these years from leap year pattern 000[04] #No year 0 and no leap year in year 4 | (?:(?:1[^0-6]|[2468][^048]|[3579][^26])00) (?# centurial years > 1500 not evenly divisible by 400 are not leap year) ) (?:(?:(?:\d\d) # century (?:[02468][048]|[13579][26]) #leap years (?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC)))|(?!.0?2))| 2[0-8]|1\d|0?[1-9]) (?<sep>[-./]) # choose a date separator (?<month> (0?[1-9])|1[012]) #end of month check (?# The maximum number of days allowed for a month has already been checked for in the month check. If you made it this far the number of day is within the range for the given month) \k<sep> # Match the same date separator choosen before. (?<year>(?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:\z|(?:\x20\d))))\d{4}(?:\x20BC)? # a four digit year. Use leading zeros if needed ) (?(?=\x20\d)\x20|$))? # if there is a space followed by a digit check for time (?<time> ( # 12 hour format (0?[1-9]|1[012]) # hours (:[0-5]\d){0,2} # optional minutes and seconds (?i:\x20[AP]M) # required AM or PM )| # 24 hour format ( [01]\d|2[0-3]) #hours (:[0-5]\d){1,2}) #required minutes optional seconds ?$)
Description
dd-mm-yyyy Datetime for AD, with leap year. See http://blogs.regexadvice.com/mash/archive/2004/04/23/1021.aspx for details on this and similar regexs
Matches
30-4-2004 | 29/2/2004 3:35 PM | 23:00:00
Non-Matches
1/31/2004 | 23:23 AM | 29/2/2005
Author Rating: Not yet rated. Michael Ash
Source
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: Re: february again
Name: Michael Ash
Date: 8/23/2005 11:05:13 AM
Comment:
Yes. It's fixed now. Good catch. Thanks.


Title: february again
Name: john
Date: 8/23/2005 10:54:03 AM
Comment:
sorry, it was 31/02...


Title: february?
Name: john
Date: 8/23/2005 10:25:03 AM
Comment:
this snippet returns true with 29/02 of any year (february 29th.) Can you reproduce this?


Title: Javascript Version
Name: Michael Ash
Date: 7/21/2004 4:47:52 PM
Comment:
A Javascript compatible version of this regex can be found at http://www.regexlib.com/REDetails.aspx?regexp_id=762


Title: Stepping back
Name: Michael Ash
Date: 7/21/2004 4:40:39 PM
Comment:
Modified to include Julian dates back to 45 BC.


Title: without most of the comments
Name: Michael Ash
Date: 6/8/2004 3:01:52 PM
Comment:
This is the above expression all but one of the comments removed for ease of use (?!(?:10(?<sep>[-./])(?:0?[5-9]|1[0-4])\k<sep>(?:1582))|(?:0?9(?<sep>[-./])(?:0?[3-9]|1[0-3])\k<sep>(?:1752))(?# both sets of missing days such not be in the same calendar so remove one or the other))(?n:^(?=\d)((?<day>31(?!.0?[469]|11)|30(?!.0?2)|29(?(.0?2)(?=.0?2.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26])))|(?!.0?2))|2[0-8]|1\d|0?[1-9])(?<sep>[-./])(?<month>(0?[1-9])|1[012])\k<sep>(?<year>\d{4})(?(?=\x20\d)\x20))?(?<time>((0?[1-9]|1[012])(:[0-5]\d){0,2}(?i:\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$) This should be one long string with no line breaks


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