Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL how to return records matching date and month only (ignore year)

Using SQL, I want to return all records where the date is between 1st March and 31st June (for example), but the records should cover all years. Is there a simple way I can achieve this?

like image 882
Olmec Avatar asked Nov 14 '22 21:11

Olmec


1 Answers

Here is what you would do if you are using PL/SQL or oracle SQL+

SELECT * FROM table
WHERE TO_CHAR(MONTH_COLUMN,'MM/DD') = '06/21'

this will give you all the rows that have a date of June 21 regardless of the year.

like image 129
Ahmad Avatar answered Dec 22 '22 04:12

Ahmad