【问题标题】:Fatal error: Call to undefined method DateTime::add()致命错误:调用未定义的方法 DateTime::add()
【发布时间】:2023-03-21 01:11:02
【问题描述】:
<?php
function OtherDAY($start,$total){

    $date = new DateTime("$start");
    $date->add(new DateInterval('P'.$total.'D'));
    $finish=$date->format('Y-m-d');
    return $finish;

}

$start=date("Y-m-d");
$otherday=OtherDAY("$start",'15');
die($otherday);`
?>`

我杀死它后它显示“不是日期格式”,如何解决这个问题

【问题讨论】:

    标签: php datetime


    【解决方案1】:

    变化:

    $date = new DateTime("$start");
    

    $date = new DateTime($start);
    

    $otherday=OtherDAY("$start",'15');
    

    $otherday=OtherDAY($start,'15');
    

    您没有将变量的值传入,因为您将其作为字符串传入

    【讨论】:

      猜你喜欢
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多