Page 1 of 1

here's a date topic for ya...

Posted: Sun Jan 08, 2006 5:22 am
by Charles256
Are dates, as long as they are formatted the same, always comparable properly?can i compare Feb. 2 to Feb. 3 to see that the first is less than the second ? in every imaginable situation? in my preliminary testing I'm inclined to say yes...but....there are a lot of combinations ;)

Posted: Sun Jan 08, 2006 5:49 am
by timvw
Yes, but instead of writing a comparator for each possible format it's probably more intelligent to convert them a simple representation (numerical / difference against an offset) and do the compare step there...

The proof that it's always possible goes as following: All dateformats / representations are a transformation (linear combination) of the numeric format (difference in seconds/hours/whatever against basetime). So if you can prove that <= is an orderrelation in the collection of natural numbers you can also prove that that relation is true in a transformation of that collection. (hmmz, time to look for my math course and come up with a more formal proof :p)

Re: here's a date topic for ya...

Posted: Sun Jan 08, 2006 9:12 am
by Weirdan
Charles256 wrote:Are dates, as long as they are formatted the same, always comparable properly?can i compare Feb. 2 to Feb. 3 to see that the first is less than the second ? in every imaginable situation? in my preliminary testing I'm inclined to say yes...but....there are a lot of combinations ;)
It appears dates are always comparable provided you're using same format and the dates are written in full form (with all three parts [year, month, day] specified). Though dates is some formats are simplier to compare, e.g. comparing unix timestamps is as easy as comparing two integers, ISO dates (YYYY-MM-DD) could be compared lexically and so on.

Re: here's a date topic for ya...

Posted: Sun Jan 08, 2006 9:32 am
by pilau
Weirdan wrote: [...] ISO dates (YYYY-MM-DD) could be compared lexically and so on.
ISO dates are what MySQL uses, right?