Forum Moderators: coopster

Message Too Old, No Replies

MKTime function

         

Modern Merlin

7:19 am on Sep 18, 2008 (gmt 0)

10+ Year Member



I have found several countdown scripts on the internet from a specific date. What I want to know is if there is a way to do it with a matter of days so that i dont have to keep changing the date.

Example: I want the code to keep counting down 15 days. Not from a specific date but just literally 15 days. Which is 360hrs.

How would I get something like:

<?php
$target = mktime(0, 0, 0, 2, 10, 2007) ;
$today = time () ;
$difference =($target-$today) ;
$days =(int) ($difference/86400) ;
print "Our event will occur in $days days";
?>

to do what I need it to do?

Thanks!

MM

webman5000

7:57 am on Sep 18, 2008 (gmt 0)

10+ Year Member



You have to specify a start date so that your script has a reference point... It needs to know 15 days from when.

Try this:


<?php
$start = mktime(0, 0, 0, 9, 17, 2008);
$target = $start+15*60*60*24; //15 days from start
$now = time();

$difference =($target-$now);
$days =(int) ($difference/86400) ;
print "Our event will occur in $days days";
?>

Modern Merlin

9:43 am on Sep 18, 2008 (gmt 0)

10+ Year Member



So essentially no matter what I do, or how I code it I will still have to come in and change the date?

penders

10:05 am on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So essentially no matter what I do, or how I code it I will still have to come in and change the date?

Not necessarily, but at some point you're going to have to set the count to 0 and store the count of days (more work and possibly less accurate - you need to use a CRON job or something and save the count in a file). Best storing a start date.

How would you envisage counting the number of days, if you didn't have a start date or reset count to 0? How would you know you were on day 5 for instance? If you didn't use a start date, your script would have to run at least once a day in order to update the count. With a start date that's not important.

Modern Merlin

10:44 am on Sep 18, 2008 (gmt 0)

10+ Year Member



Aaaah Ok. That makes sense.

Thank you both for your help! Guess Ill work with what is out there as I need this to be as accurate as possible. No sense re-inventing the wheel ;)

MM