chiprivers Posted October 5, 2011 Share Posted October 5, 2011 Please could somebody help me with this, I assume, pretty simple SQL where clause... I have a DATE column in my table (field is called reviewdate) and I would like to return all records where the value in this column is within the current month. Could somebody help with the WHERE clause? Something like... WHERE functionformonthandyearof(reviewdate) = functionforcurrentmonthandyear() Many thanks in advance. Link to comment https://forums.phpfreaks.com/topic/248470-date-column-is-within-current-month/ Share on other sites More sharing options...
awjudd Posted October 5, 2011 Share Posted October 5, 2011 Is this what you want? WHERE MONTH(reviewdate) = MONTH(CURDATE()) ~juddster Link to comment https://forums.phpfreaks.com/topic/248470-date-column-is-within-current-month/#findComment-1275989 Share on other sites More sharing options...
chiprivers Posted October 5, 2011 Author Share Posted October 5, 2011 That looks good but do I also need to specify the year also to ensure that it only returns entries with a matching month in the current year and not say all records with a review date in October every year? Link to comment https://forums.phpfreaks.com/topic/248470-date-column-is-within-current-month/#findComment-1276002 Share on other sites More sharing options...
PFMaBiSmAd Posted October 5, 2011 Share Posted October 5, 2011 WHERE EXTRACT(YEAR_MONTH FROM reviewdate) = EXTRACT(YEAR_MONTH FROM CURDATE()) Link to comment https://forums.phpfreaks.com/topic/248470-date-column-is-within-current-month/#findComment-1276004 Share on other sites More sharing options...
chiprivers Posted October 5, 2011 Author Share Posted October 5, 2011 thank you - that looks like it will work - will give it a go Link to comment https://forums.phpfreaks.com/topic/248470-date-column-is-within-current-month/#findComment-1276013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.