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条)

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染