Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Michael Ash's Regex Blog

Regex Musings

Not Dates again


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  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.

  1. Let's start with what calendar I'm using. All my date regexs use the Gregorian calendar.

  2.     What are Leap Years and when do they occur?


 if you need a second opinion

  3. my date regexs by category    

    • VB= Works with VB regex engine
    • JS= Works with javascript (should work in most regex) engines
    • 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.
    1. Gregorian 4 digit years ranging from 1600-9999

      1. mm/dd/yyyy :
        1. 2 or 4 digit year. 00 fails as leap year for 2 digit years. (VB,JS, D)
        2. DT

          1. (VB, JS, DT)
          2. (VB, NC, DT)
      2. dd/mm/yyyy:

        1. (VB,NC,  DT)
        2. (VB,JS, DT)
      3. c) yyyy/mm/dd: Four digit years ranging from 1600-9999

        1. (VB, NC DT)
        2. (VB, JS, D)
        3. mmm dd, yyyy

          1. (VB,JS, D)
        4. dd mmm yyyy

          1. ((VB,JS, D)
          2. mm/dd/yyyy Julian and Gregorian. Four digit years ranging 0001-9999. includes missing days

            1. (VB, NC, DT)
          3. dd/mm/yyyy Julian and Gregorian. Four digit years ranging 0001-9999. includes missing days

            1. (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

              Published Friday, April 23, 2004 1:00 AM by mash
              Filed under:



              mash said:

              Great stuff Mike; thanks for posting this, it will be a great article to send people to. There's no doubt about it - you are the RegexDates KING! :)
              April 23, 2004 2:11 AM

              mash said:

              i've been watching you sir michael ash. i've been an avid reader of your articles especially on regex. you are really great! and the creation of this blog of yours regarding dates is another great thing you've done for humanity lolz (at least those who spends most of their lives on cyber world) ^_^

              i'll save this link for future refernnce ^_^
              June 4, 2004 6:03 AM

              Michael Ash's Regex Blog said:

              Several year ago I decided to learn Regular Expressions. I had been skimming over an article about using

              November 1, 2011 9:01 AM

              Regex dates | Yourmanfriend said:

              August 24, 2012 6:25 PM
              Anonymous comments are disabled