我正在尝试将日期与 MySQL 数据库中的日期进行比较,该日期距当前日期大于 90、60、30 天。我正在使用 DateTime 对象,它很容易操作,但在获取我正在寻找的响应时遇到了问题。任何帮助深表感谢。
<?php
//date_default_timezone_set('America/Chicago');
$todaysDate = new DateTime('now');
$formattedDate = $todaysDate->format('Y-m-d');
$date = new DateTime ('now');
$date90 = $date->add(new DateInterval('P90D'));
$date90 = $date->format('Y-m-d');
$date = new DateTime ('now');
$date60 = $date->add(new DateInterval('P60D'));
$date60 = $date->format('Y-m-d');
$date = new DateTime ('now');
$date30 = $date->add(new DateInterval('P30D'));
$date30 = $date->format('Y-m-d');
//echo $date90;
//echo "<br />";
//echo $formattedDate;
$thirtyDays = array();
$sixtyDays = array();
$ninetyDays = array();
$sql = "SELECT * FROM service;";
if(!$result = $con->query($sql)){
die('There was an error running the query [' . $con->error . ']');
}else{
//$numRows = $result->num_rows;
while($row = $result->fetch_array()){
$boosterDate = $row['boosterDate'];
}
}
if($boosterDate > $date90){
echo "greater than 90 days";
echo "<br />";
}
?>