Connecting Tech Pros Worldwide Help | Site Map

Comparing month and year from a timestamp

  #1  
Old January 7th, 2009, 08:10 PM
gregerly's Avatar
Expert
 
Join Date: Sep 2006
Posts: 189
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 08:25 PM. Reason: Fixed the problem.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing Two Dates Using PHP from MYSQL Database ameshkin answers 2 April 9th, 2006 02:05 AM
Question from php cookbook Mike answers 5 December 14th, 2005 12:05 PM
if/else statement for perl script? Stuart H answers 3 July 19th, 2005 05:48 AM
How to inspect array elements based on criteria? deko answers 18 July 17th, 2005 08:20 AM