RE: [PHP-DB] Compare time functions

2002-09-30 Thread John W. Holmes

> 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




[PHP-DB] Compare time functions

2002-09-30 Thread wade

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?

Thank you

--
Should you have any questions, comments or concerns, feel free to call
me at 318-338-2033.

Thank you for your time,

Wade Kelley, Design Engineer

Bayou Internet...(888) 30-BAYOU...http://www.bayou.com
Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net
Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com





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