...

View Full Version : Querying a time format



Trinity-Links
03-09-2009, 12:25 AM
Hi,

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)

Thanks

PappaJohn
03-09-2009, 12:38 AM
SELECT * FROM blog WHERE DATE_FORMAT(blogdate , '%M-%Y') = 'March-2009' ORDER by blogdate DESC

Trinity-Links
03-09-2009, 12:46 AM
cheers very muchly....

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

Thanks again:):):)

PappaJohn
03-09-2009, 12:52 AM
You're welcome

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


SELECT * FROM blog
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