Php 如何将天添加到时间戳

Php 如何将天添加到时间戳,php,time,Php,Time,如何将天添加到时间戳并回显时间。 我试着给它加上几天的时间,但当echo显示为“否”时 $timestamp = strtotime('+7 days', $row['sdate']); 这个代码是否正确 谢谢你应该是这样的 $date = strtotime($row['sdate']); $date = strtotime("+7 day", $date); echo date('Y-m-d H:i:s',$date); 或者你也可以像这样尝试 $date = strtotime('+7

如何将天添加到时间戳并回显时间。 我试着给它加上几天的时间,但当echo显示为“否”时

$timestamp = strtotime('+7 days', $row['sdate']);
这个代码是否正确

谢谢你应该是这样的

$date = strtotime($row['sdate']);
$date = strtotime("+7 day", $date);
echo date('Y-m-d H:i:s',$date);
或者你也可以像这样尝试

$date = strtotime('+7 days', strtotime($row['sdate']) );
echo date('Y-m-d',$date);

strotime函数需要unix时间戳,所以您需要转换您的时间(我希望是正常的datetime)

然后,如果要再次将其格式化为datetime,请执行以下操作:

$timestamp = strtotime('+7 days', strtotime($row['sdate']) );
echo date("Y-m-d H:i:s", $timestamp);
您可以在php手册上阅读更多关于strottime和date的内容。


thnx..但是我现在如何回显新的日期。如果我必须在时间戳中添加一些天并将新的时间戳存储回数据库,我如何将$date转换为时间戳..因为我认为使用strotime将更改其数据类型(它将不再保留时间戳..会吗?),那么该怎么办?
$timestamp = strtotime('+7 days', strtotime($row['sdate']) );
echo date("Y-m-d H:i:s", $timestamp);