dqk42179 2014-11-24 13:45
浏览 76

使用星期几获取日期

In PHP, how could I calculate the date of all days in a week using day of the week number and the current date?

My code:

 $daynumber=date("N",time());
 $date = date("l j F Y", strtotime("+ ".$daynumber." days"));

EDIT:

I have a scheduler script and I'm trying to get the date of every day of the week like this in a table:

 Monday   Tuesday   Wednesday   Thursday   Friday
 24-11    25-11     26-11       27-11      28-11
  • 写回答

1条回答 默认 最新

  • duanjue2560 2014-11-24 13:49
    关注

    I think I don't understand your question properly, but you can get the start and end date for a week with the current week and year for example..

    function getStartAndEndDate($week, $year) {
      $dto = new DateTime();
      $ret['week_start'] = $dto->setISODate($year, $week)->format('Y-m-d');
      $ret['week_end'] = $dto->modify('+6 days')->format('Y-m-d');
      return $ret;
    }
    
    评论

报告相同问题?