检索错误 ate_diff() 期望参数 2 为 DateTimeInterface
Retrieving error ate_diff() expects parameter 2 to be DateTimeInterface
我想首先声明,我已经查看了以前给出答案的线程,但是在实施解决方案时。我收到以下回复。对于与此问题相关的任何类型的回复,我将不胜感激。
**Project description:**
我被分配了一项任务,根据用户使用 post 请求输入的日期计算今天日期与万圣节前剩余天数之间的时差。
Fault codes
警告:date_diff() 期望参数 2 为 DateTimeInterface,在
中给出为 null
致命错误:在
中的非对象上调用成员函数 format()
**Html code:**
<!DOCTYPE HTML>
<html>
<head>
<title>Hallowen kalkylering</title>
<meta charset="UTF-8" />
<meta keywords="Hallowen, kalkylera" />
<link rel="stylesheet" href="stil.css">
</head>
<style>
id {
text-align: center;
}
button {
position: absolute;
top: 50%;
}
</style>
<body>
<body background="https://s3-us-west-2.amazonaws.com/i.cdpn.io/328575.rrRQYW.2f211232-53fc-4b59-952f-baf9951e2cba.png">
<div id="title">
<h1 style="text-align: center; color: red;">Kalkylera dagar till Hallowen</h1>
</div>
<div id="Formular" class="formular">
<form action="Kalkyl.php" method="POST">
<center><label style="" for="idag">Dagens datum</label>
När är 万圣节?
</body>
PHP代码:
<!DOCTYPE html>
达加尔克瓦尔
</head>
<body>
<center><p> Nedräknare </p></center>
<?php
echo "<center>$idagny</center>";
"<br>";
echo "<center> men mamma hur många dagar är det kvar till hallowen?</center>" ;
"<br>";
$idag = $_POST["idag"];
$idagny = new datetime("2017/10/20");
$Hallowendatum = new datetime("2017/10/31");
$dagarkvar = date_diff($idagny,$hallowendatum);
echo $dagarkvar->format("%R%a days");
"<br>"
?>
</body>
此致,
大卫
$Hallowendatum 与 $hallowendatum 不同。它们的大小写应该相同。
此外,由于 date_diff 会在失败时 return false,因此最好在您的代码中进行检查。进行某种错误处理,而不是让 PHP 致命
我想首先声明,我已经查看了以前给出答案的线程,但是在实施解决方案时。我收到以下回复。对于与此问题相关的任何类型的回复,我将不胜感激。
**Project description:**
我被分配了一项任务,根据用户使用 post 请求输入的日期计算今天日期与万圣节前剩余天数之间的时差。
Fault codes
警告:date_diff() 期望参数 2 为 DateTimeInterface,在
中给出为 null
致命错误:在
中的非对象上调用成员函数 format()**Html code:** <!DOCTYPE HTML> <html> <head> <title>Hallowen kalkylering</title> <meta charset="UTF-8" /> <meta keywords="Hallowen, kalkylera" /> <link rel="stylesheet" href="stil.css"> </head> <style> id { text-align: center; } button { position: absolute; top: 50%; } </style> <body> <body background="https://s3-us-west-2.amazonaws.com/i.cdpn.io/328575.rrRQYW.2f211232-53fc-4b59-952f-baf9951e2cba.png"> <div id="title"> <h1 style="text-align: center; color: red;">Kalkylera dagar till Hallowen</h1> </div> <div id="Formular" class="formular"> <form action="Kalkyl.php" method="POST"> <center><label style="" for="idag">Dagens datum</label>
När är 万圣节?</body>
PHP代码:
<!DOCTYPE html>
达加尔克瓦尔
</head> <body> <center><p> Nedräknare </p></center> <?php echo "<center>$idagny</center>"; "<br>"; echo "<center> men mamma hur många dagar är det kvar till hallowen?</center>" ; "<br>"; $idag = $_POST["idag"]; $idagny = new datetime("2017/10/20"); $Hallowendatum = new datetime("2017/10/31"); $dagarkvar = date_diff($idagny,$hallowendatum); echo $dagarkvar->format("%R%a days"); "<br>" ?> </body>
此致,
大卫
$Hallowendatum 与 $hallowendatum 不同。它们的大小写应该相同。
此外,由于 date_diff 会在失败时 return false,因此最好在您的代码中进行检查。进行某种错误处理,而不是让 PHP 致命