Connecting Tech Pros Worldwide Help | Site Map

Comparing month and year from a timestamp

gregerly's Avatar
Expert
 
Join Date: Sep 2006
Posts: 189
#1: Jan 7 '09
Hello, I've got a question regarding the comparison of a date and year to a timestamp. I've got blog entries that get a timestamp on their way into my database (mysql). I'm programming an "archives" section, and I can't seem to select the info using month and year. Basically what I want to do is say:

select all artices where the month of the timestamp = $given_month AND year of the timestamp = $given_year.

To accomplish the above I tried (note: blog_date is the timestamp in the db):

SELECT * FROM blog_entries WHERE MONTH(blog_date) = 'january' AND YEAR(blog_date) = 2009.

The error I'm getting is unknown column MONTH(blog_date), etc....

How do I go about selecting articles based on the timestamp when given the month and year of the article?

Thanks!

Greg

UPDATE: I've resolved the issue. It seems the CodeIgniter PHP framework likes to auto protect field names (and was doing so incorrectly) in my queries. I got it all worked out. Thanks!
Reply