Itβs bad to use alphabet rules for date processing, mainly because you run into problems when things are sorted differently according to alphabet and number system
For the alphabet
01-02-2011 comes before 01-1-2011 (because 0 in the date field is before 1 in the other date field)
For a numerical system
01, 02, 2011 comes after 01, 1, 2011 because all fields are being compared like numbers
Date objects extend the numerical comparison to know which fields have an advantage when comparing, so you donβt get an earlier month by putting the date βearlierβ than another, which actually happens in the last month but earlier year.
If you have strict control over the date format, you can agree on dates so that they also comply with alphabetical rules; however, you run the risk that your entire program will fail if you accidentally enter an incorrect date.
A typical way to do this (not recommended, use comparisons other than String Date)
YYYYMMDD (year)(month)(day) all zero-padded.
The last method is included mainly because you will eventually see it in the wild and must recognize it for what: an attempt to process dates without an appropriate date library (aka smart hack).
Edwin buck
source share