xionhack Posted January 4, 2009 Share Posted January 4, 2009 Hello. I want to make a loop that will display tuesday, saturday, saturday, saturday, tuesday, saturday, saturday, saturday... etc, but with their exact dates. Let's say this week 1/6/2009, 1/10/2009, 1/10/2009, 1/10/2009, 1/13/2009, 1/17/2009, 1/17/2009, 1/17/2009.... etc, how can i do that?! Thanks Quote Link to comment Share on other sites More sharing options...
Clinton Posted January 4, 2009 Share Posted January 4, 2009 How long is this supposed to go on? Quote Link to comment Share on other sites More sharing options...
xionhack Posted January 4, 2009 Author Share Posted January 4, 2009 Per month. All of the tuesdays and saturdays in the current month, and I want to make a button to move to the next month. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 4, 2009 Share Posted January 4, 2009 Here's one solution; <?php function getdays($start,$which) { $res = array(); $st = strtotime(date('Ym01',strtotime($start))); $end = strtotime('+1 month',$st); $fd = strtotime('first ' . $which,$st); for ($i = $fd;$i<$end; $i+=604800) $res[] = $i; return($res); } $days = array_merge(getdays('20090201','saturday'),getdays('20090201','tuesday')); sort($days); foreach($days as $d) echo date('l, F jS, Y',$d) . "\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.