jcstanley Posted March 30, 2007 Share Posted March 30, 2007 Hi What i am trying to do is select all events from a table where month is equal to the current month. For example: Name Date .... Event 1 2007-03-01 Event 2 2007-03-28 Event 3 2007-04-14 The current month is March (03) so only Event 1 and Event 2 should be selected. I have a variable which contains the current month value: $currentmonth=date("m"); but i am not sure how to incorporate this into the query: $query = "SELECT raceid, name, DATE_FORMAT(date, '%d %M %y') AS formatted_date, time, lowtime, lowheight FROM racing WHERE ???????? ORDER BY 'formatted_date' ASC"; Any suggestions greatly appreciated Thanks Link to comment https://forums.phpfreaks.com/topic/44933-solved-select-from-mysql-based-on-month-value/ Share on other sites More sharing options...
obsidian Posted March 30, 2007 Share Posted March 30, 2007 If you only need selections from the current month, you don't even have to use a variable: SELECT * FROM racing WHERE MONTH(date) = MONTH(CURDATE()); If you prefer to use the variable, just fill it in: SELECT * FROM racing WHERE MONTH(date) = '$m'; See more about date and time functions in the MySQL manual. Good luck! Link to comment https://forums.phpfreaks.com/topic/44933-solved-select-from-mysql-based-on-month-value/#findComment-218200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.