Date formats

Wikidot's Documentation

The current format specified in the Wikidot NewPage Module's documentation is this:

format="/^(19|20)\d\d(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])$/"

This is incorrect, as there is no separator between the year and the month, and it will only accept YYYYMM DD formatted dates. In addition to this, it will only cater for years in the 20th and 21st centuries. The format should be specified like so:

format="/^[\d]{4}[- \/.](0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])$/"

Improvement: Days/Month

The above dating format is a simple one; it neglects the correct number of days in each month. The below dating schemes ensure a more valid date (with the exception of validating leap-years).

YYYY MM DD

format="/^(19|20)\d\d[- \/.](0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))$/"

MM DD YYYY

format="/^(0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))[- \/.](19|20)\d\d$/"

DD MM YYYY

format="/^((0[1-9]|[12][0-9]|3[01])[- \/.]0[13578]|(0[1-9]|[12][0-9]|30)[- \/.]0[469]|(0[1-9]|[12][0-9])[- \/.]02|(0[1-9]|[12][0-9]|3[01])[- \/.]1[02]|(0[1-9]|[12][0-9]|30)[- \/.]11)[- \/.](19|20)\d\d$/"

DD MM YYYY or MM DD YYYY or YYYY MM DD (Not Recommended)

format="/^((((0[1-9]|[12][0-9]|3[01])[- \/.]0[13578]|(0[1-9]|[12][0-9]|30)[- \/.]0[469]|(0[1-9]|[12][0-9])[- \/.]02|(0[1-9]|[12][0-9]|3[01])[- \/.]1[02]|(0[1-9]|[12][0-9]|30)[- \/.]11)[- \/.](19|20)\d\d)|((0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))[- \/.](19|20)\d\d)|((19|20)\d\d[- \/.](0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))))$/"

Improvement: Leap Years

As the above code treats every year as a leap year, there may be times where the user inputs an invalid year. This following code interprets a leap year as one that's a multiple of 4. So it's not 100% accurate, but it's pretty damn close!

YYYY MM DD

format="/^(\d\d([02468][048]|[13579][26])[- \/.](0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30)))|(\d\d([02468][1235679]|[13579][01345789])[- \/.](0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|1[0-9]|2[0-8])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30)))$/"

MM DD YYYY

format="/^((0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))[- \/.]\d\d([02468][048]|[13579][26]))|((0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|1[0-9]|2[0-8])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))[- \/.]\d\d([02468][1235679]|[13579][01345789]))$/"

DD MM YYYY

format="/^(((0[1-9]|[12][0-9]|3[01])[- \/.]0[13578]|(0[1-9]|[12][0-9]|30)[- \/.]0[469]|(0[1-9]|[12][0-9])[- \/.]02|(0[1-9]|[12][0-9]|3[01])[- \/.]1[02]|(0[1-9]|[12][0-9]|30)[- \/.]11)[- \/.]\d\d([02468][048]|[13579][26]))|(((0[1-9]|[12][0-9]|3[01])[- \/.]0[13578]|(0[1-9]|[12][0-9]|30)[- \/.]0[469]|(0[1-9]|1[0-9]|2[0-8])[- \/.]02|(0[1-9]|[12][0-9]|3[01])[- \/.]1[02]|(0[1-9]|[12][0-9]|30)[- \/.]11)[- \/.]\d\d([02468][1235679]|[13579][01345789]))$/"

DD MM YYYY or MM DD YYYY or YYYY MM DD (Not Recommended)

format="/^((((0[1-9]|[12][0-9]|3[01])[- \/.]0[13578]|(0[1-9]|[12][0-9]|30)[- \/.]0[469]|(0[1-9]|[12][0-9])[- \/.]02|(0[1-9]|[12][0-9]|3[01])[- \/.]1[02]|(0[1-9]|[12][0-9]|30)[- \/.]11)[- \/.]\d\d([02468][048]|[13579][26]))|(((0[1-9]|[12][0-9]|3[01])[- \/.]0[13578]|(0[1-9]|[12][0-9]|30)[- \/.]0[469]|(0[1-9]|1[0-9]|2[0-8])[- \/.]02|(0[1-9]|[12][0-9]|3[01])[- \/.]1[02]|(0[1-9]|[12][0-9]|30)[- \/.]11)[- \/.]\d\d([02468][1235679]|[13579][01345789]))|((0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))[- \/.]\d\d([02468][048]|[13579][26]))|((0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|1[0-9]|2[0-8])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))[- \/.]\d\d([02468][1235679]|[13579][01345789]))|(\d\d([02468][048]|[13579][26])[- \/.](0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|[12][0-9])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30)))|(\d\d([02468][1235679]|[13579][01345789])[- \/.](0[13578][- \/.](0[1-9]|[12][0-9]|3[01])|0[469][- \/.](0[1-9]|[12][0-9]|30)|02[- \/.](0[1-9]|1[0-9]|2[0-8])|1[02][- \/.](0[1-9]|[12][0-9]|3[01])|11[- \/.](0[1-9]|[12][0-9]|30))))$/"

Not Recommended

It's not recommended to use the combination date formats (the code that accepts DMY, MDY and YMD formats). This can make it ambiguous when people enter dates that are less than the 13th day of the month, which section represents the day or the month. This becomes a problem when people enter dates in the DMY format AND the MDY format.

page_revision: 28, last_edited: 1256962438|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License