因此,在我的数据库中,我有regdate(日期类型),但是无论它是什么日期,代码始终返回1。
<?php
$con = mysqli_connect("localhost","root","","login");
if (mysqli_connect_error()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM users");
$row = $result->fetch_array();
$date1 = new DateTime($row['regdate']);
$date2 = new DateTime("now");
$interval = $date1->diff($date2);
echo "It has been " .$interval->d." days ";
//$interval is supposed to be difference between regdate and todays date
我希望我不要错过任何愚蠢的事情。谢谢您的答复。
解决了
最佳答案
我相信这可能会更容易。
SELECT DATEDIFF(NOW(),$row['regdate']);
而且我认为您需要一个while循环才能找到所有记录。