如何在php中计算10天后的日期?

问题描述 投票:2回答:5

假设$start_date = 2017-12-13

我想知道10天后应该约会的日期。

我试过这个strtotime("$start_date +10 days"),输出是1512946800

php date strtotime
5个回答
5
投票

您将时间戳作为值,现在您只需要将其格式化为最新版本。

date("y-m-d HH:mi:ss", strtotime("$start_date +10 days"))
date("Y-m-d", strtotime("$end_date -10 days")); //for minus

那应该照顾它。


3
投票

为什么不使用DateTime

$start_date = "2017-12-13";
$date = new DateTime($start_date);
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d') . "\n";

输出

2017-12-23

demo


2
投票

使用DateTime更容易

$start_date = "2017-12-13";
$date = new DateTime($start_date);

echo $date->modify('+10 day')->format('Y-m-d');

1
投票
echo  date("Y-m-d", strtotime("+10 days", strtotime($start_date)));

你试试如上。从“+10天”替换为您想要的值,以获得您希望添加的天数。


1
投票

使用php strtotime()函数获取10天后的日期。 strtotime()函数它给出了未来日期的unix时间戳,现在使用date()函数格式化它

$start_date = "2017-12-13";
$future_date =strtotime("$start_date +10 days");//it will give the unix timestamp of the future date, now format it using date() function as
$future_date=date("Y-m-d H:i:s", $future_date);

查看qazxsw poi手册

© www.soinside.com 2019 - 2024. All rights reserved.