我只是想问我如何过滤Mysql中的时间戳值?
假设我们有以下日期时间
1351128031
1351128045
1351128097
如何使用这种格式创建日期范围?如何在查询中执行此操作?
像这样:
SELECT * FROM user
WHERE acct_created BETWEEN (datefrom) AND (dateto) -- my problem is I can't filter the timestamp
您想使用一个名为 UNIX_TIMESTAMP
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp的 mysql 函数
SELECT * FROM user
WHERE acct_created BETWEEN UNIX_TIMESTAMP('datefrom') AND UNIX_TIMESTAMP('dateto')
其中 datefrom 和 dateto 是格式化为字符串的日期,类似于 UTC 中的 '2012-01-01 00:00:00'
下面是 MySQL 选择查询:
select *,
UNIX_TIMESTAMP(`Timestamps`)
from Table1
where UNIX_TIMESTAMP(`Timestamps`) between 1351128040 and 1351128099