MySQL Mysql时间戳查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3665223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql time stamp queries
提问by James
I have a column that uses time stamp. My question is I am a bit confused about how to make queries against it,how would I say
我有一个使用时间戳的列。我的问题是我对如何对其进行查询有点困惑,我该怎么说
Where $time is after X date
$time 在 X 日期之后的位置
Are queries made in local time or CUT?
查询是在当地时间还是 CUT 进行?
When I just try to do where andthe post date /time I get an error because of the space and if I quote it I think it takes it as a string : /
当我只是尝试做在哪里和发布日期/时间时,我会因为空间而出错,如果我引用它,我认为它将它作为一个字符串:/
What format do I use for the date in the WHERE clauss !?!?
WHERE 子句中的日期使用什么格式!?!?
回答by Adam Morris
You can use the normal logical comparisons, for example:
您可以使用正常的逻辑比较,例如:
SELECT * FROM table WHERE date >= '2010-01-31'
SELECT * FROM table WHERE date >= '2010-01-31 12:01:01'
Time is generally in your current local time, but you can run the query "SELECT CURTIME()" to check. Also, make sure you have the year-month-date in the right order... that can cause issues.
时间通常是您当前的本地时间,但您可以运行查询“SELECT CURTIME()”进行检查。另外,请确保您按正确的顺序排列了年月日……这可能会导致问题。
The manual has more details:
该手册有更多详细信息:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
回答by Mchl
Assuming you talk about TIMESTAMP column type (not Unix timestamp) the format is either 'YYYY-MM-DD HH:MM:SS'
(quoted) or YYYYMMDDHHMMSS
假设您谈论 TIMESTAMP 列类型(不是 Unix 时间戳),格式是'YYYY-MM-DD HH:MM:SS'
(引用)或YYYYMMDDHHMMSS
Atually, in the first case you can use any spearators you wish (or none), only numbers are taken into ccount
Atually,在第一种情况下,您可以使用任何您希望(或不使用)的spearators,只考虑数字