PHP <-> MySQL Timestamp Storage and Comparison
| From: | Gary Singleton | Date: | Fri, 29 Sep 2000 23:50:47 +0000 |
| Subject: | PHP <-> MySQL Timestamp Storage and Comparison | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-18144@lists.php.net to get a copy of this message | ||
I am trying to find the best way of storing time values in MySQL so I can compare them later. What
I want to accomplish is this:
Add a file to my database - $date_original
Update that file - $date_updated
Today's date - $date_current
Right now all I'm doing is comparing time(); results like this:
// seconds in one day = 60 * 60 * 24 = 86400
$day = 86400;
$date_current = time();
$date_updated = time() - ($day * 10); // to test values
$date_original = time() - ($day * 10); // to test values
echo time();
if (($date_updated - $date_original) <= ($day * 3) && ($date_current - $date_updated)
<= ($day * 3)) {
echo "new";
}
elseif (($date_updated - $date_original) > ($day * 3) && ($date_current - $date_updated)
< ($day * 3)) {
echo "updated";
}
else {
echo "old";
}
This works just fine so what I am considering is storing the updated and original in my database as
an unsigned bigint which should allow values up to 18446744073709551615.
I'm thinking that this probably isn't the best solution though so if anyone has a better
plan please let me know. I'm really looking for the simplest solution, not necessarily the
most efficient. Oh, it just needs to be close too - not exact.
TIA, G.
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com