dpdt79577 2016-09-20 04:38
浏览 31
已采纳

在php mysql中获取与今​​天时间戳匹配的行

I have table in mysql with three fileds

id
name
time_stamp

here time_stamp stores php time() value.

I want to get the fields that matches todays timestamp ,now i am fetching all rows and check time stamp condition in the loop if it matches will print the current row.

Is there anyway to do this in mysql query itself?

  • 写回答

4条回答 默认 最新

  • doufu7464 2016-09-20 04:51
    关注

    Since you insert unix timestamps (time()), you don't need to fetch all rows and make a comparison on the fetching. Just use FROM_UNIXTIME() in MySQL:

    SELECT * FROM table_name WHERE FROM_UNIXTIME(`time_stamp`, '%Y-%m-%d') = CURDATE()
    

    Fiddle

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

报告相同问题?