Andy Williams
Andy Williams

Reputation: 907

Query on partial date search

So I am trying to figure out the correct syntax on the following. Basically I have a Datetime Column that I need do search ONLY on the "DD-MM". I am having a hard time with the syntax and can't seem to ask the right question on the good ol' interwebs. Here is my example.

I need this:

SELECT someDate FROM someTable

WHERE someDate = 'YYYY-MM-DD HH:MM:SS'

To Look like this:

  SELECT someDate FROM someTable

  WHERE someDate = 'MM-DD'

Upvotes: 0

Views: 638

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270431

Many databases support to_char() (or a similar function):

where to_char(someDate, 'MM-DD') = 'MM-DD'

More support functions to extract month and date:

where month(someDate) = MM and day(someDate) = DD

The standard functions are a bit more verbose:

where extract(month from someDate) = MM and extract(day from someDate) = DD

Upvotes: 2

Related Questions