【发布时间】:2012-05-25 09:44:03
【问题描述】:
我知道关于 SO 的大量日期问题,但我被这个问题难住了。
我需要生成一些报告,为此我需要计算出一些日期。
报告将在周一运行,我需要计算出前一周的周日和下周六的日期。
例如该报告将在 5 月 28 日星期一运行,我需要的日期是 5 月 20 日星期日和 5 月 26 日星期六。
然后我需要相同的值,但对于前一周,即 5 月 13 日星期日和 5 月 19 日星期六。
我认为这部分会很好,因为它只是获取运行报告时的星期一的当前日期并从那里进行操作的情况。
THEN 最后,我不能解决的部分是我提到的第一周,我需要去年的对应日期,所以周日和周六的日期来自同一周数在上一年。
我知道日期函数可以为您提供周数,但不知道如何根据此计算出该周的星期日和上一个星期六的日期。
这是我的,请原谅 OTT 变量名:
$today = date('Y/m/d');
// reports run on a Monday and use last Sunday and the following Saturday's date so get yesterday's date first
$yesterday = strtotime ('-1 day', strtotime($today));
$yesterday = date ('Y/m/d', $yesterday);
// start of week (last Sunday)
$start_of_last_week = strtotime ('-1 week', strtotime($yesterday));
$start_of_last_week = date ('Y/m/d', $start_of_last_week);
// end of last week (the following Saturday)
$end_of_last_week = strtotime ('+ 6 days', strtotime($start_of_last_week));
$end_of_last_week = date ('Y/m/d', $end_of_last_week;
// start of previous week
$start_of_previous_week = strtotime ('-1 week', strtotime($start_of_last_week));
$start_of_previous_week = date ('Y/m/d', $start_of_previous_week);
// end of previous week
$end_of_previous_week = strtotime ('+ 6 days', strtotime($start_of_previous_week));
$end_of_previous_week = date ('Y/m/d', previous;
// the start of the same week last year
$start_of_last_week_last_year = strtotime ('-1 year', strtotime($start_of_last_week ));
但上面的不正确所以不知道下一步该怎么做。
非常感谢任何帮助。
【问题讨论】:
-
啊,谢谢,我确实尝试过搜索,但不是那种特定的措辞。我相信这将是一个很大的帮助,谢谢!