note 27701 added to function.date
| From: | paul at rack1 dot php dot net | Date: | Mon, 16 Dec 2002 14:29:41 +0000 |
| Subject: | note 27701 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40964@lists.php.net to get a copy of this message | ||
There are several people here trying to add/subtract from timestamp values in MySQL. This *can*
work, but it can also go horribly wrong.
The correct way is to do something like this:
$query = "SELECT DISTINCT foo1, foo2, foo3 FROM
table WHERE TO_DAYS(NOW()) -
TO_DAYS(foo2) <= 7 ORDER BY foo2 ASC;"
MySQL then works out 7 days prior to NOW. Even if today was the 6th, for example.
Of course, if time was decimalised, things would be so much easier!
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+27701
http://master.php.net/manage/user-notes.php?action=delete+27701
http://master.php.net/manage/user-notes.php?action=reject+27701