If you use a TIMESTAMP or DATETIME column, you can write a subroutine to convert that into an "seconds since the epoch" number.
This isn't necessary. The UNIX_TIMESTAMP MySQL function takes a datetime (any date type column) as an argument and returns the epoch of the time passed; such as: SELECT UNIX_TIMESTAMP(myDateCol) FROM TABLE;
Also, MySQL has another function called INTERVAL that allows you to do math on the date in the database itself, such as: select * from table where myDateCol < current_date - interval 5 day; will show you everything older than five days ago.
When doing database programming, the hardest thing for me to get over was to try and do everything in the program (in Perl, in C, etc) when the database is (in _most_ cases) going to be able to do it for you a lot more efficiently and a lot faster. Let the database do it's job.. it likes it, really. |