[thelist] comparing a TIMESTAMP(6) entry in mysql to today's date

Anthony Baratta Anthony at Baratta.com
Fri Sep 13 10:17:01 CDT 2002


At 05:02 AM 9/13/2002, Dunstan Orchard wrote:

>I have an entry in a mysql db called 'date_posted'. I am grabbing it in php
>like this:
>
>$date_posted = mysql_result($result, $i,"date_posted");
>
>It's a TIMESTAMP(6) column, so the date returned is in the 020907 format (for
>7th of September 2002).
>
>
>I want to take that date, compare it to today's date (which php can generate)
>and work out if the difference is less than/equal to 30 days, or greater than
>30 days.

Convert the format of the TimeStamp into a useful format using the
DATE_FORMAT() function:

http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1293

e.g.

Select DATE_FORMAT(TimeStamp_Col,'%m/%d%/%y') From Table_Name Where RowID =
'11'
---
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."




More information about the thelist mailing list