我只想问一下如何在Mysql中过滤时间戳值?
假设我们将以下日期时间作为
1351128031
1351128045
1351128097
如何使用此格式创建日期范围? 如何在查询中执行此操作?
像这样:
SELECT * FROM user
WHERE acct_created BETWEEN (datefrom) AND (dateto) -- my problem is I can't filter the timestamp
答案 0 :(得分:2)
您想使用名为UNIX_TIMESTAMP
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
SELECT * FROM user
WHERE acct_created BETWEEN UNIX_TIMESTAMP('datefrom') AND UNIX_TIMESTAMP('dateto')
其中datefrom和dateto是格式化为字符串的日期,类似于UTC中的“2012-01-01 00:00:00”