Connecting Tech Pros Worldwide Help | Site Map

Comparing month and year from a timestamp

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 7th, 2009, 07:10 PM
gregerly's Avatar
Expert
 
Join Date: Sep 2006
Posts: 188
Default Comparing month and year from a timestamp

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!

Last edited by gregerly; January 7th, 2009 at 07:25 PM. Reason: Fixed the problem.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.