php MYSQL select all from table where 月份?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6731854/
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 select all from table where month?
提问by Mirgorod
is it possible to select all fields with some month?
是否可以选择某个月份的所有字段?
For example: I have column 'create_date' and values of this column:
例如:我有“create_date”列和该列的值:
2011-05-06 11:12:13 (this)
2012-06-06 13:12:13
2010-02-06 14:52:13
2011-05-06 21:12:13 (this)
2001-08-06 16:12:13
2011-09-06 18:12:43
2009-01-06 11:12:13
2012-02-06 12:17:55
2010-03-06 14:15:13
2012-05-06 11:19:23 (this)
How to select all fields where month equals to 05?
如何选择月份等于05的所有字段?
回答by Nicola Peluchetti
You could use
你可以用
SELECT create_date FROM table WHERE MONTH(create_date) = 5
回答by genesis
SELECT * FROM your_table WHERE month(create_date) = 5
look at documentationThis query works on datetime type of column
查看文档此查询适用于日期时间类型的列
回答by mce
SELECT * FROM table WHERE MONTH(create_date) = 5
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month
回答by CloudyMarble
Use month(Yourdate)
to extract the month
使用 month(Yourdate)
一个月来提取
回答by TD_Nijboer
just stumbled upon something to mention when using MONTH() it will only get the month from a DATE string. not from a unixtimestamp
在使用 MONTH() 时偶然发现了一些要提及的内容,它只能从 DATE 字符串中获取月份。不是来自unixtimestamp
if you want to use it with a unixtimestamp try:
如果您想将它与 unixtimestamp 一起使用,请尝试:
MONTH(FROM_UNIXTIME(create_date))
回答by Breith
For a dynamic filtering of the current month :
对于当月的动态过滤:
MONTH(create_date) = MONTH(NOW())
回答by steveregs
Use this query
使用此查询
SELECT
create_date
FROM
table
WHERE
MONTHNAME(create_date) = MONTHNAME(now())
回答by TheSystem
You could do something like:
你可以这样做:
select create_date from "table" where create_date between '2011-05-01' and '2011-05-31';