X weeks and X days left to

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
June73
Forum Newbie
Posts: 3
Joined: Wed Jul 30, 2008 11:38 am

X weeks and X days left to

Post 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!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: X weeks and X days left to

Post 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.
June73
Forum Newbie
Posts: 3
Joined: Wed Jul 30, 2008 11:38 am

Re: X weeks and X days left to

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: X weeks and X days left to

Post 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
June73
Forum Newbie
Posts: 3
Joined: Wed Jul 30, 2008 11:38 am

Re: X weeks and X days left to

Post 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
Post Reply