0

我正在尝试让 strtotime 制作日期范围,我已经弄清楚了一些基本的。

这是我想弄清楚的一些内容,但我找不到您应该在网上任何地方为这些内容键入的格式:

$startDate = strtotime('first day of last month');
$endDate = strtotime('last day of last month');
$startDate = strtotime('first of last week');
$startDate = strtotime('first of this week');

这些是我唯一找不到参考的,它们可能需要特殊的编程并且没有strtotime参考。

编辑:看起来我的代码应该可以工作,但 PHP 5.2 中有一个错误

我使用了一种解决方法来到达上个月的第一天。

这有效: $firstDayOfLastMonth = strtotime(date('Ym', strtotime('last month')))

4

1 回答 1

1

对于你可以使用的一周

strtotime('this week midnight'); // returns Monday midnight of this week
strtotime('last week midnight'); // returns Monday midnight of last week

如果您想要从星期一开始的一周,则此方法有效。上周似乎假设星期一是第一天。如果您想要从星期日开始的一周的时间戳,请使用以下命令:

strtotime('last week Sunday midnight'); // returns Sunday midnight of this week
strtotime('-2 weeks Sunday midnight'); // returns Sunday midnight of last week
于 2012-04-17T16:39:40.973 回答