PDA

View Full Version : Find Month in Database Field



Bassman
03-23-2008, 12:40 PM
I have a database text field that contains birth dates with just the month/day listed. I would like to find the records that contain just the month that is this month.
Like WHERE 'birth_date' = $this_month

How would I break this apart?

felgall
03-23-2008, 01:54 PM
WHERE DATE_FORMAT('birth_date','%m')=$this_month

Bassman
03-23-2008, 04:32 PM
You know how women are about their age. I don't have a date field. I only have a text field with data like 7/12 or 11/19.
I tried explode("/",'birth_date',1) = month(now()) and I get an error. But I do have a lot of empty fields.
Thanks

felgall
03-24-2008, 12:25 AM
Possibly:

SUBSTRING(birth_date,LOCATE('/',birth_date)+1)=MONTH(CURDATE())

Bassman
03-24-2008, 12:24 PM
Thanks for putting me on the right track. I had to modify it a little. The correct code was :
WHERE SUBSTRING(birth_date,1,LOCATE('/',birth_date)-1)=MONTH(CURDATE())");

felgall
03-24-2008, 12:45 PM
oops, forgot you have the date backwards where you live.