如何计算去年同一周数中特定日期的日期


How to calculate the dates of particular days in the same week number from last year?

我知道SO上有大量的日期问题,但我对此感到困惑。

我需要运行一些报告,为此我需要计算一些日期。

该报告将在星期一运行,我需要计算出前一周和下周六的星期日日期。

例如,报告将在 5 月 28 日星期一运行,我需要的日期是 5 月 20 日星期日和 5 月 26 日星期六。

然后我需要相同的值,但对于前一周,所以 5 月 13 日星期日和 5 月 19 日星期六。

我认为这部分会很好,因为它只是获取运行报告的星期一的当前日期并从那里进行操作的情况。

最后,我无法计算的部分是我提到的第一周,我需要去年的相应日期,因此来自前一年同一周编号的星期日和星期六的日期。

我知道日期函数可以为您提供周数,但无法看到如何根据该周的星期日和上一个星期六的日期计算出来。

这就是我所拥有的,请原谅 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 ));

但是上面是不对的,所以不知道下一步该怎么做。

任何帮助都非常感谢。

您可以像这样查找特定年份和周数的星期一日期

date( 'Y-m-d', strtotime( '2012W21' )); //2011-05-23

复合日期格式