View Full Version : Querying a time format

03-08-2009, 11:25 PM

Im creating a blog ... when I click on a date (March-2009) I want msql to query all the posts in March-2009

obviously the database has stored the date as something like "2009-03-01"

Im playing around with the query:

SELECT * FROM blog WHERE blogdate = DATE_FORMAT('March-2009' , '%M-%Y') ORDER by blogdate DESC
but it doesnt seem to do anything..

am I barking up the wrong tree (ie. wrong msql command)


03-08-2009, 11:38 PM
SELECT * FROM blog WHERE DATE_FORMAT(blogdate , '%M-%Y') = 'March-2009' ORDER by blogdate DESC

03-08-2009, 11:46 PM
cheers very muchly....

I can see where I went wrong now....Mind u, it is past me bed time!

Thanks again:):):)

03-08-2009, 11:52 PM
You're welcome

Old Pedant
03-10-2009, 12:22 AM
I think you will find you will get better efficiency if you code

WHERE YEAR(blogdate) = 2009 AND Month(blogdate) = 3
ORDER by blogdate DESC

I assume you can easily pass in the numbers 2009 and 3 (or whatever) from whatever server language you are using.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum