Adding seven days to date

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
Crew
Forum Newbie
Posts: 16
Joined: Fri Jul 15, 2005 4:05 am

Adding seven days to date

Post by Crew »

Hi

I want to list all the mondays in the year, I can find the 1st using

Code: Select all

$date = date('Y-m-d',strtotime('this monday',mktime(0,0,0,1,1,2005)));
But how do I add 7 days to loop through this in Y-m-d format for the next year? Results will be displayed in a dropdown.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

store the results of the strtotime()..something like this

Code: Select all

$start = strtotime('this monday',mktime(0,0,0,1,1,2005));
for($time = $start;date('Y',$time) == 2005; $time = strtotime('+7 day',$time)) {
  echo date('Y-m-d',$time)."\n";
}
Post Reply