0

I'm looking to just select a certain month and date (12/25), but don't care about the year. I tried this

WHERE DAY(date) = 25 AND MONTH(date) = 12;

But that didn't work. Any way to just search month and day? The field is timestamp without time zone.

gf7
  • 145
  • 11
  • 1
    Tag your question with the database you are using. And "didn't" work is not helpful. What is the issue. – Gordon Linoff Dec 20 '20 at 02:16
  • 1
    is any error message displayed? if yes, can you please add that to your question? – a121 Dec 20 '20 at 02:17
  • Take a look for this answer [https://stackoverflow.com/questions/851236/where-clause-to-find-all-records-in-a-specific-month](https://stackoverflow.com/questions/851236/where-clause-to-find-all-records-in-a-specific-month) – Sagar Kumar Dec 20 '20 at 02:23

2 Answers2

3

The SQL standard syntax would be:

where extract(day from date) = 25 and
      extract(month from date) = 12

Most databases, however, support the day() and month() functions.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

This may solve your problem. I tested using MySQL.

SELECT ... FROM Table t WHERE MONTH(name_column) = :month AND DAY(name_column) = :day
Mohit Kushwaha
  • 1,003
  • 1
  • 10
  • 15