954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MySQL return month and date from NOW()

I am unclear how to write a query where I want all the entries in a specific month and date format from a MySQL table. I am not using DATE_FORMAT() with a NOW() correctly. I need to write a query that has a time field in the yyyy-mm-dd format to return all entries that match today’s month and date. I would appreciate your assistance.
Thanks
WBR

rouse
Junior Poster
114 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

I should list what I have tried:
SELECT DATE_FORMAT(NOW(), '%M %D') returns "December 27th"

And

Select * from TIME_TABLE
Where
Extract(month from DATE_FIELD ) = 12
and
Extract(day from DATE_FIELD ) = 26
order by DATE_FIELD, DESCRIPTION

returns a result set, but

Select * from TIME_TABLE
Where
Extract(month from DATE_FIELD ) = DATE_FORMAT(NOW(), '%M')
and
Extract(day from DATE_FIELD ) = DATE_FORMAT(NOW(), '%D')
order by DATE_FIELD, DESCRIPTION

Returns an empty result set, so I think I need to figure out how to get the month and date as intergers.

rouse
Junior Poster
114 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

I was finally successful with this format:
Extract(month from DATE_FIELD ) = DATE_FORMAT(NOW(), '%c')
and
Extract(day from DATE_FIELD ) = DATE_FORMAT(NOW(), '%e')
And I found the format examples and explanations at this site:

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

rouse
Junior Poster
114 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You