is it possible to select all fields with some month?
For example: I have column 'create_date' and values of this column:
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?
MONTH() function in MySQL is used to find a month from the given date. It returns 0 when the month part for the date is 0 otherwise it returns month value between 1 and 12.
To get the year and the month columns, use the EXTRACT(part FROM date) function. In this solution, the part argument is replaced by YEAR and MONTH to get the year and the month separately, each in its own column. You can learn more about EXTRACT() in the official MySQL documentation.
We can retrieve the current month value in SQL using the MONTH() and DATEPART() functions along with the GETDATE() function. To retrieve the name of the month functions in SQL such as DATENAME() and FORMAT() are used.
For a dynamic filtering of the current month :
MONTH(create_date) = MONTH(NOW())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With