Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP的HTML代码中添加2个月的日期?_Php_Html_Date - Fatal编程技术网

如何在PHP的HTML代码中添加2个月的日期?

如何在PHP的HTML代码中添加2个月的日期?,php,html,date,Php,Html,Date,我是PHP新手,我想在html代码中为特定日期添加2个月。我怎么做?请引导我通过 以下是我使用的代码: private function inputExpiryDate() { $value = $this->expiryDate; $html = ""; $html .= '<label for="expirydate">Expiry Date:</label>'; $html .= '<input type="tex

我是PHP新手,我想在html代码中为特定日期添加2个月。我怎么做?请引导我通过

以下是我使用的代码:

    private function inputExpiryDate() {
    $value = $this->expiryDate;
    $html = "";
    $html .= '<label for="expirydate">Expiry Date:</label>';
    $html .= '<input type="text" readonly name="expirydate" id="expirydate" value="'.$value.'">';
    $html .= '<input type="button" id="expirydatebutton" onclick="getExpiryDate()">' . PHP_EOL;
    return $html;
}

非常感谢您的帮助。

您只需像这样添加
date('Y-m-d)
日期('Y-m-d',strotime('date('Y-m-d',strotime($date))。“+1个月”)您不必分解
$date
值,就可以在进行相关日期更改时使用它。这应该像预期的那样工作:

$date = date('Y-m-d', strtotime("$date +1 month"));
之后

添加行

echo date("Y-m-d", $date);

因为第一句话将返回Unix时间戳,所以您需要再次将其转换为可读格式

当您添加$value=strottime(日期(“Y-m-d”,strottime($value))。“+1个月”)时会发生什么;$html=“”;)之前;?谢谢Mate这很简单。不会否定它,但是你的例子不适用于d/m/Y
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
echo date("Y-m-d", $date);