开发者

php - list of dates coming up

All the users are in the United States. I need to be able to list all weekdays besides today. So say that it's Thursday, October 7. It should start by listing Friday, October 8 and then Monday, October 11.

I kno开发者_如何学Gow how to make sure I'm only listing weekdays when looping through, but the trouble I have is making sure tomorrow is tomorrow. In the past it's changed at about 8:00 at night eastern time. I'm thinking I'd like to have is so when it's maybe 12:00 pacific time to count it as the next day.


<?php
   $current = new DateTime('now');
   $last = new DateTime('saturday');
   while ($current < $last) {
      echo $current->format('l, F j'), "\n";
      $current->modify('+1 day');
   }
?>


You can use strtotime to get the date of the next days and you can use date to determine if a date is a week day :

<?php
$reference = time(); // We set today as the first day //

for ($i=0, $j=0; $i<5; $i++, $j++) {
   $nextDay = strtotime('+' . $j . ' days', $reference);
   if (date('w', $nextDay) > 0 && date('w', $nextDay) < 6) {
       echo date('r', $nextDay), "\n";
   } else {
       $i--;
   }
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜