[英]MySQL: Select data from a table where the date falls in the current Week and current Month
[英]MYSQL select all from table where month?
是否有可能在某個月份對所有字段進行 select?
例如:我有列“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)
如何 select 月份等於 05 的所有字段?
你可以使用
SELECT create_date FROM table WHERE MONTH(create_date) = 5
SELECT * FROM your_table WHERE month(create_date) = 5
查看文檔此查詢適用於日期時間類型的列
SELECT * FROM table WHERE MONTH(create_date) = 5
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month
只是在使用 MONTH() 時偶然發現了一些要提及的內容,它只會從 DATE 字符串中獲取月份。 不是來自unixtimestamp
如果您想將它與 unixtimestamp 一起使用,請嘗試:
MONTH(FROM_UNIXTIME(create_date))
使用month(Yourdate)
提取月份
對於當前月份的動態過濾:
MONTH(create_date) = MONTH(NOW())
您可以執行以下操作:
select create_date from "table" where create_date between '2011-05-01' and '2011-05-31';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.