How to select rows that have current day's timestamp?

后端 未结 9 1608
渐次进展
渐次进展 2020-11-28 21:14

I am trying to select only today\'s records from a database table.

Currently I use

SELECT * FROM `table` WHERE (`timestamp` > DATE_SUB(now(), INTE         


        
相关标签:
9条回答
  • 2020-11-28 22:13

    Simply cast it to a date:

    SELECT * FROM `table` WHERE CAST(`timestamp` TO DATE) == CAST(NOW() TO DATE)
    
    0 讨论(0)
  • 2020-11-28 22:14
    SELECT * FROM `table` WHERE timestamp >= CURDATE()
    

    it is shorter , there is no need to use 'AND timestamp < CURDATE() + INTERVAL 1 DAY'

    because CURDATE() always return current day

    MySQL CURDATE() Function

    0 讨论(0)
  • 2020-11-28 22:15

    On Visual Studio 2017, using the built-in database for development I had problems with the current given solution, I had to change the code to make it work because it threw the error that DATE() was not a built in function.

    Here is my solution:

    where CAST(TimeCalled AS DATE) = CAST(GETDATE() AS DATE)

    0 讨论(0)
提交回复
热议问题