RE: [PHP] Messing with Dates
| From: | Craig Vincent | Date: | Tue, 29 Aug 2000 18:10:53 +0000 |
| Subject: | RE: [PHP] Messing with Dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14198@lists.php.net to get a copy of this message | ||
> I'm assuming that your last_updated field has the DATETIME datatype. You
> have first of all to convert that to a UNIX timestamp, and then compare to
> the substraction of the timestamp of "right now" and a month ago. I'm also
> assuming that "a month ago" means 30 days. You might want to check for 31
> day months if you are really paranoid.
Why not let mktime do the check...then it will handle 30/31 (and 28) day
months properly :)
<?
$last = mysql_query(...);
list($hour, $min, $sec, $day, $mon, $yr) = explode(" ",date("H i s d m y"));
if (date('Y-m-d H:i:s',mktime($hour, $min, $sec, $mon-1, $day, $yr) > $last)
{
echo 'More than a month has passed';
}
else {
echo 'Less than a month has passed';
}
?>
Of course you may need to change the format for date depending on whether
you used a DATE, DATETIME or TIMESTAMP(x) column.
Sincerely,
Craig Vincent
-------------------------
Senior Programmer
Jazzmonkey Media Inc.
http://www.jazzmonkey.com
-------------------------