Skip to content
Prev 155412 / 398513 Next

How to preserve date format while aggregating

Hi Erich,

Since min() is defined for numbers and not dates, the problem is in the
min() function. min() is converting from date format to number format.

Your best bet is to make this conversion explicit...such that it is
reversable. So, convert the date into UTC, then UTC to seconds since epoch,
then take the minimum, then convert back to UTC time.

This sounds like a pain...but that's basically what a version of min()
designed to work with dates would do. The reason this is a pain is basically
due to timezones:

Consider a comparison between x = 3:54 PM September 8 in California (right
now where I am) and y = 12:54 AM September 9 in Zurich (right now where you
are). Is it earlier here than there? Yes, because it's Sept 8 to your Sept
9. Is it earlier there than here? Yes, because your day started 56 minutes
ago, mine over 15 hours ago. Is it the same time here than there? Yes,
because our UTC times are equal.

So it's not clear what min should return, so min is not defined for dates.
However, min is defined for numbers, and dates can be converted to
numbers...but what those numbers actually mean is not necessarily clear.

--Adam
On Mon, 8 Sep 2008, Erich Studerus wrote: