472,125 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

Comparing month and year from a timestamp

192 Expert 100+
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?



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!
Jan 7 '09 #1
0 1867

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Job Lot | last post: by
3 posts views Thread by Robert Dell | last post: by
1 post views Thread by DaveA | last post: by
3 posts views Thread by Bryan | last post: by
19 posts views Thread by Ricardo Perez Lopez | last post: by
2 posts views Thread by ameshkin | last post: by
12 posts views Thread by colincolehour | last post: by
3 posts views Thread by whatchamakeofit | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.