On Fri, 22 Jun 2001 06:41, george wrote:
>   My back is aganist the wall with this one, I have to create a timer .
>
>  What happens is  admin will enter a time say 2 hours in the future
> this time will be stored in a db as a time stamp
> then the current time and the timestamp from the db are subtracted from
> one another and the result is shown as hours minutes and seconds.
>   but I cant get it to work at all
> any suggestions would be great
>
>
> TIA
>  George

Better than my previous effort :-):

<?php
$now = time();  //Get current timestamp
$then = mktime(0,0,0,6,23,2001); // What you get from the DB
$diff = $then - $now;
echo "Starting with $diff seconds. Check days<BR>";
$days = floor($diff / 86400);
$seconds_left = $diff % 86400;
echo "Days: $days<BR>";
echo "Seconds remaining: $seconds_left<BR>";
$hours = floor($seconds_left / 3600);
$seconds_left = $seconds_left % 3600;
echo "Hours: $hours<BR>";
echo "Seconds remaining: $seconds_left<BR>";
$minutes = floor($seconds_left / 60);
$seconds_left = $seconds_left % 60;
echo "Minutes: $minutes<BR>";
echo "Seconds remaining: $seconds_left<BR>";
?>

You might want to add a check on wheter $now is earlier or later that he 
value in the DB, and act accordingly.


-- 
David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  

   If you're not confused, you're not paying attention.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to