MySQL select based on daily timestamp range

时间秒杀一切 提交于 2019-12-11 02:19:51

问题


I am trying to select data from a table based on timestamps (stored as int(10)). The timestamps correspond to unix timestamps. I am using MySQL 5.

Question: How can I select the data based on the following rule: get all records, where the timestamp is from 9 to 10 o'clock. Nothing else. Timestamp could be in the 70's or today.


回答1:


If you're storing the value as a UNIX timestamp, you'll need to convert the value into MySQL's timestamp format before using the HOUR function.

WHERE HOUR(FROM_UNIXTIME(`timestamp`)) = 9



回答2:


Use HOUR() (assuming column is called timestamp)

WHERE HOUR(FROM_UNIXTIME(`timestamp`)) = 9


来源:https://stackoverflow.com/questions/14539268/mysql-select-based-on-daily-timestamp-range

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