2

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user3505049
  • 139
  • 2
  • 3
  • 11

2 Answers2

4

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.

cincura.net
  • 4,130
  • 16
  • 40
1
select
extract(MONTH from cast('2002-02-02' as date))
from rdb$database
rstrelba
  • 1,838
  • 15
  • 16