Select only month from timestamp in mysql query to archive articles by month
Hi. I am a beginner in MySQL and have a question. I've used the same code to return all rows in the database table. Now I want to specify criteria for the date column (timestamp) to only return articles in that specified month.
Here is my query:
$query ="SELECT entrytitle, entrytext, entryurl, ";
$query.=" DATE_FORMAT(entrydate, '%M %d, %Y ' '-' ' %l:%i%p') AS date";
$query.=" FROM blog ORDER BY entrydate DESC LIMIT $startrow, $display";
I've been researching and playing around w/ the code for about 2 days. I guess I want something along the lines of this:
$query.=" DATE_FORMAT(entrydate, '%M') AS date WHERE entrydate = $month ";
However, that doesn't seem to be working. Maybe that's complete wrong or maybe it's syntax...I don't know.
This is specified earlier in the code (in case you're wondering):
$month = $_GET["month"];
I really want to do this in MySQL query because it's suppose to be much easier than doing all the conversions in PHP.
I will greatly appreciate your time and any help given.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread