假设$start_date = 2017-12-13
。
我想知道10天后应该是什么。
我尝试了此strtotime("$start_date +10 days")
,输出为1512946800
您将时间戳作为值,现在您只需要与日期格式化。
date("y-m-d HH:mi:ss", strtotime("$start_date +10 days"))
date("Y-m-d", strtotime("$end_date -10 days")); //for minus
应该照顾的。
为什么不使用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
echo date("Y-m-d", strtotime("+10 days", strtotime($start_date)));
您尝试如上所述。从" 10天"替换为您所需的价值,以获取所需的天数。
使用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);
在此处检查php strtotime()
使用dateTime,它更容易
$start_date = "2017-12-13";
$date = new DateTime($start_date);
echo $date->modify('+10 day')->format('Y-m-d');