MySQL select based on daily timestamp range

2019-07-18 11:14发布

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.

2条回答
\"骚年 ilove
2楼-- · 2019-07-18 11:35

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
查看更多
够拽才男人
3楼-- · 2019-07-18 11:51

Use HOUR() (assuming column is called timestamp)

WHERE HOUR(FROM_UNIXTIME(`timestamp`)) = 9
查看更多
登录 后发表回答