设置strtotime将变量添加到天数

时间:2016-03-02 17:22:50

标签: php strtotime

我正在尝试导出特定天数并将其设置为变量$ max_future。目前它是一个固定的天数,但我希望用户输入变量是它所拥有的数字。

目前设置为:

$max_future = date("Y-m-d", strtotime($today . "+6 days"));

我想要类似的东西:

$exportDays = '9'; //(or whatever the user input was)
$max_future = date("Y-m-d", strtotime($today . "+$exportDays days"));

这可能吗?我感谢任何帮助

3 个答案:

答案 0 :(得分:1)

尝试:

$max_future = date("Y-m-d", strtotime($today . "+" . $exportDays . " days"));

答案 1 :(得分:0)

这样的事情:

<?php
$output = 9; // you can take this value from input.
$today = date("Y-m-d");
echo date('Y-m-d', strtotime($today. ' +'.$output. ' days'));
?>

答案 2 :(得分:0)

<?php
    $exportDays = $_REQUEST['exportDays']; // or however you want to get it from user input
    $max_date = date('Y-m-d', strtotime(date('Y-m-d') . ' +' . $exportDays . ' days'));