September 08, 2003

Database as a time calculator

I had took look up in the Postgres manual to see how Timestamps work(Can you believe that my last week's job at work is to port the product to a new database!!??) and was amazed to find so many useful time related functions there.

We used to joke about writing a wrapper class and use the database for inappropriate tasks but now it is far more tempting once I saw how easy it is in SQL99 to calculate how many days to my next birthday.

select timestamp '2004-05-28' - now() AS tmp FROM setting;

If you see code like datediff( con, d1, d2 ) from now on you'll know why. (Evin Grin).

Posted by stuartcw at September 8, 2003 05:49 PM
Comments