Search code examples
sqldatetimefirebirdflamerobin

How to select dates with same day and month (ignoring year) using firebird


I have a database where users stores their birthday. y-m-d, and I'm trying to get every user that has the same birthday; the year can be different between each user.

So how do I turn this to a working script:

SELECT username FROM table_name WHERE birthday='$birthday'

$birthday gets its data from a form, where the inputs is example: 2002-02-02. And if users have this birthday it should echo it out. But the problem is that it checks with the year, and I'm trying to only get month and day, not year.

I have tried with EXTRACT(MONTH FROM ...) but didn't get it to work. What am I missing?


Solution

  • You should store your data as DATE. Then the date/time like EXTRACT functions will work.

    I recommend adding new column and filling it with data from the original one using CAST. Then dropping the original column. Also consider using parameters instead of string concatenation to prevent SQL injection.