I had pretty much decided I wasn't going to talk anymore about dates, for awhile at least. Despite the fact I had created a newer version of my datetime regex. But a recent comment made it seem needed. I've posted 11 different date regexs to the www.Regexplib.com site. Each is a little different from the other.
Some are just dates, some are datetime, some are mm/dd/yyyy some dd/mm/yyyy or yyyy/mm/dd. The one thing they have in common is that they all work as they are suppose to. They all handle leap years correctly I've received lots of comments that would make you think otherwise. Now its not like I haven't messed up a regex before. And if I receive a comment point out those errors I appreciate them because that allow me to correct my mistakes. But most of the negative comment are just incorrect statements. They are arguments for invalid points. Apparently exactly what a Leap Year is and when they occurs is not as common knowledge as I thought.. I've gotten several comments telling me what is and isn't a leap year none of which have been correct. So I'm just going to gather info all my date regexs here so I cant refer people to this blog where I can have links to documentation on the subject.
- Let's start with what calendar I'm using. All my date regexs use the Gregorian calendar.
What are Leap Years and when do they occur?
http://aa.usno.navy.mil/faq/docs/leap_years.html if you need a second opinion
my date regexs by category
- VB= Works with VB regex engine
- NC= uses named captures
- DT= Datetime = Date and/or time
- D = Date only.
- Date separators / . - must be paired. No mixing separtors within a date string.
Gregorian 4 digit years ranging from 1600-9999
- mm/dd/yyyy :
- 2 or 4 digit year. 00 fails as leap year for 2 digit years. http://regexlib.com/REDetails.aspx?regexp_id=113 (VB,JS, D)
- http://regexlib.com/REDetails.aspx?regexp_id=369 (VB, JS, DT)
- http://regexlib.com/REDetails.aspx?regexp_id=504 (VB, NC, DT)
- http://regexlib.com/REDetails.aspx?regexp_id=505 (VB,NC, DT)
- http://regexlib.com/REDetails.aspx?regexp_id=610 (VB,JS, DT)
c) yyyy/mm/dd: Four digit years ranging from 1600-9999
- http://regexlib.com/REDetails.aspx?regexp_id=581 (VB, NC DT)
- http://regexlib.com/REDetails.aspx?regexp_id=190 (VB, JS, D)
mmm dd, yyyy
- http://regexlib.com/REDetails.aspx?regexp_id=404 (VB,JS, D)
dd mmm yyyy
- http://regexlib.com/REDetails.aspx?regexp_id=405 ((VB,JS, D)
mm/dd/yyyy Julian and Gregorian. Four digit years ranging 0001-9999. includes missing days
- http://regexlib.com/REDetails.aspx?regexp_id=644 (VB, NC, DT)
dd/mm/yyyy Julian and Gregorian. Four digit years ranging 0001-9999. includes missing days
- http://regexlib.com/REDetails.aspx?regexp_id=691 (VB, NC, DT)
About the Julian and Gregorian regexs (3f and 3g)
These expressions remove the range restriction of the year and validate for all A.D. Dates
They are both based on the premise of the switch from the Julian calendar in 1582 to the Gregorian. The match missing days in 1752 are included but don't really belong for the conversion in 1582. The link to the details of the missing days are included in the comment of the regex
I hope this clears up the confusion