> Could anyone help me to figure out how to write a piece of code that
> says
> if the time now time( ) is greater than 1 hour of the time( time
stored
> in the database) do something.
> 
> I have a script that gets the time as of now and I also have the time
of
> (lets say then) stored in a database.
>  how would I write the code to say if the old time is greater than 1
> hour do
> something?
> 
> I need to compare the 2 time( ) functions.
> $time1 = current server time
> $time2 = server time stored in the database
> 
> if ($time1 is >= 1 hour of $time2)
>     {
>     execute code
>     }
> 
> How would one go about comparing these two time functions?

Well, if you want to do the comparison in PHP, you can select out all of
the rows and loop through them all. Use UNIX_TIMESTAMP(column_name) in
your query to get out the unix timestamp of the date column, instead of
the mysql format. Then..

$now = time();
if($now - $db_time > 3600)
{
        //more than an hour old
}

You could do it in your query like this:

SELECT * FROM your_table WHERE db_time_column < NOW() - INTERVAL 1 HOUR;

That'll return all rows that have a db_time_column that's more than an
hour old. Adapt that to an update or delete query and you're good to go.

---John Holmes...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to