如何使用strtotime获得一个月内每周的开始和结束日期?

时间:2015-04-03 15:41:08

标签: php date strtotime

我需要从星期一到星期五每周获取数据,我需要将它分开几周。第1周需要是该月的第一周(如果第一周是MON-FRI),但是从第一周开始,到周五结束。 例如,4月第1周将是周三1日至周五3日一直到第5周是周一27日到周四30日(本月最后一天) 我遇到的问题是,如果本月的第一天是在星期六或星期日,并且几周被抛弃,它就会出现偏差。

   $week1start = date('m/01/Y',strtotime("this month"));
   $week1end = date('m/d/Y',strtotime("first friday of this month"));
   $week2start = date('m/d/Y',strtotime("first monday of this month"));
   $week2end = date('m/d/Y',strtotime("second friday of this month"));
   $week3start = date('m/d/Y',strtotime(" second monday of this month"));
   $week3end = date('m/d/Y',strtotime("third friday of this month"));
   $week4start = date('m/d/Y',strtotime("third monday of this month"));
   $week4end = date('m/d/Y',strtotime("fourth friday of this month"));
   $week5start = date('m/d/Y',strtotime("fourth monday of this month"));
   $week5end = date('m/30/Y',strtotime("this month"));

0 个答案:

没有答案