duandu5846 2013-10-06 11:05
浏览 7
已采纳

检查数据库中的日期是现在还是更早

I have a php script that looks like this (shortened/edited for clarity of course):

$result = mysqli_query($link, 'SELECT date FROM table');
while ($row = mysqli_fetch_assoc($result)) {
if ($row["date"] < time())
{
do some stuff
}
else
do something else

The date is stored in a DATE field in MySQL. I have no interest in storing time and only the date is stored in that field in XXXX-XX-XX format.

How can I check if the retrieved date is today or earlier? By using time() there, which was the last thing I ended up trying, my script is acting as if all retrieved dates are today or earlier, even when they are not.

Thank you for any help with this.

  • 写回答

2条回答 默认 最新

  • duancaishun4812 2013-10-06 11:16
    关注

    You should perform the comparison in the SQL query.

    Have a look at: mysql date comparison with date_format

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?