[PHP] PHP <-> MySQL Timestamp Storage and Comparison From: Gary Singleton (gsinglet2 <email protected>)
Date: 09/29/00

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  <email protected> address at http://mail.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>