Mysql: Find entries from specific day using timestamp column

跟風遠走 提交于 2020-03-26 07:31:25

问题


My each row have time-stamp column (called 'timestamp'). How can I find all rows from specific day?

I've tried calculating start/end of the day, but i'm looking for a better way.


回答1:


You need to extract just the date part, using DATE() function:

SELECT *
FROM yourtable
WHERE DATE(your_column) = '2013-07-03'

or you can use this, that can make use of an index:

SELECT *
FROM yourtable
WHERE your_column >= '2013-07-03' AND
      your_column < '2013-07-03' + INTERVAL 1 DAY



回答2:


use the date function:

select date('2013-07-03 15:58:37');


来源:https://stackoverflow.com/questions/17449920/mysql-find-entries-from-specific-day-using-timestamp-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!