Page 1 of 1

X weeks and X days left to

Posted: Wed Jul 30, 2008 12:02 pm
by June73
I'm looking for a simple countdown-to-date script that outputs for an example "8 weeks and 5 days left to D day"
I have searched the net but just can't find anything!
I'm a total PHP newbie unfortunately so I don't know how to make the script without any direction.
Any help and direction is greatly appreciated!

Re: X weeks and X days left to

Posted: Wed Jul 30, 2008 12:43 pm
by jayshields
Subtract the countdown date from todays date. Then divide the amount of days difference by 7 (using floor) to find out how many weeks, then use the modulus operator (obviously, again, by 7) on the day difference to find the number of remaining days after the given amount of weeks calculated previously. Then print the first result for the weeks and the second result for the days.

Re: X weeks and X days left to

Posted: Wed Jul 30, 2008 1:11 pm
by June73
OK! Thank you! Remember i'm a total newbie so please forgive me if I ask dumb questions.
I have a countdown script that i'm altering.

To get the weeks this is what you mean right?

Code: Select all

 
// weeks left
$weeksleft = floor(((strtotime($dday) - strtotime($today)) / 86400) / 7);
Then I'm lost unfortunately. I don't know what you mean by "the modulus operator"? (i'm located in sweden)
I get the print part though, not just the "daysleft" snippet.
jayshields wrote:Subtract the countdown date from todays date. Then divide the amount of days difference by 7 (using floor) to find out how many weeks, then use the modulus operator (obviously, again, by 7) on the day difference to find the number of remaining days after the given amount of weeks calculated previously. Then print the first result for the weeks and the second result for the days.

Re: X weeks and X days left to

Posted: Wed Jul 30, 2008 2:33 pm
by jayshields
The modulus operator is %. It calculates the remainder of a division, for example if there are 32 days and you already know how many weeks there are, then this will tell you how many days are left after those amount of weeks

Code: Select all

echo 32 % 7; //4

Re: X weeks and X days left to

Posted: Wed Jul 30, 2008 2:49 pm
by June73
OK, thank you for your answer. I have to play a bit with it and try to understand your instructions, it's pretty much greek to me but I'll get it working hopefully =)
jayshields wrote:The modulus operator is %. It calculates the remainder of a division, for example if there are 32 days and you already know how many weeks there are, then this will tell you how many days are left after those amount of weeks

Code: Select all

echo 32 % 7; //4