简体   繁体   English

SQL - 从现在到六个月前提取时间戳的数据

[英]SQL - pulling data where timestamp is between now and six months ago

I would like to get data that's within the last 6 months.我想获取过去 6 个月内的数据。 I have a time stamp stored but its stored as an int(11) rather then time stamp in the database.我存储了一个时间戳,但它存储为 int(11) 而不是数据库中的时间戳。

would would be the correct sql statement to pull this data?将是提取此数据的正确 sql 语句吗? (below is the statement I have tried but pulls 0 results - possibly due to the fact its stored as int rather then timestamp) (以下是我尝试过的语句,但得出 0 个结果 - 可能是因为它存储为 int 而不是时间戳)

SELECT * FROM `Main_Stats` WHERE `Dates` >= now() - INTERVAL 6 month

Try this for mysql:为 mysql 试试这个:

SELECT * FROM `Main_Stats`
WHERE from_unixtime(`Dates`,'%Y-%m-%d') >= now() - INTERVAL 6 month

You probably want a unix_timestamp .你可能想要一个unix_timestamp

Try this尝试这个

SELECT * FROM `Main_Stats` WHERE `Dates` >= unix_timestamp(now()-interval 6 month)

Try this code试试这个代码

SELECT * 
FROM `Main_Stats`
WHERE `Dates` >= DATEADD(MONTH, -6, GETDATE()) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM