1

这是我到目前为止所拥有的:

$date = date('Y-m-d h:i:s', strtotime('-7 days')); 
$start = date('Y-m-d h:i:s', strtotime($date,'previous Sunday'));

输出 $start 时返回:1969-12-31 06:00:00

我究竟做错了什么?

4

4 回答 4

4

$date需要一个时间戳

$date = strtotime('-7 days'); 
$start = date('Y-m-d h:i:s', strtotime('previous Sunday',$date));
于 2011-01-18T23:13:40.087 回答
2

你有错误的论点:

date('Y-m-d h:i:s', strtotime('previous Sunday', $date));

编辑:此外,您制作$date了一个格式化的字符串。它必须是时间戳,因此您的代码应如下所示:

$date = strtotime('-7 days'); 
$start = date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
于 2011-01-18T23:07:44.437 回答
0

每个php 文档

date('Y-m-d h:i:s', strtotime('last Sunday', $date));
于 2011-01-18T23:12:16.020 回答
0

如果您的日期不是时间戳,您仍然可以使用strtotime,例如假设您的日期已经传入并且是另一种字符串格式。

$date = '2013-11-10';
$lastsunday = date('Y-m-d',strtotime($date.' last Sunday'));

这可以节省一些时间尝试将您的日期转换为“有效”的格式

于 2014-02-17T03:10:45.700 回答