create timer

A

Anonymous

Guest
Hi guys,

I want to offer something to my clients for a limited time only and i want to let them know the time left before the promotion end... assuming that the last day for the offer is 20 of aug 2004, how can I set a program so that we can tell people how many days and hours left for them to take action?

i tried js but it doesn't seem to work coz the js will only runs when people load the page and the timer will shows different time on other computers if they access different time.. i want all people to view the same time left no matter where and when they view it,,, something like the timer auction websites have.

please advise..
 
This is fairly simple date arithmetic and there are already plenty of scripts out there that do this. Basically the "time left" is the difference between the expiry date and right now. So you'd have some code like this:

Code:
<?php
$now = mktime(); // right now, in UNIX time (seconds)
$enddate = mktime(0,0,0, 8, 20, 2004); // 12:00 a.m. on August 20, 2004

// the number of seconds between right now and enddate
$secs_til_enddate = $enddate - $now;
?>

That gives you the number of seconds between right now and the end date. Then it's just some simple math to figure out how many days, hours, minutes, etc. that equals. E.g.:

Code:
<?php
$days_til_enddate = $secs_til_enddate / (60*60*24);
?>

You can use floor() or ceil() to round up or down, of course.
 
Back
Top