MoFish Posted November 28, 2013 Share Posted November 28, 2013 Hi,Is it possible to get the last date of a month in mysql on a start date variable? Example... WHERE date >= '$date' and date <= GETLASTDAY('$date'): I'm aware this wont work - but may help understand what i'm trying to achieve.I currently pass in a variable called $date which has a value of "2013-11-01" . I'm hoping to execute a mysql query where it would figure out the last possible date in that month based on the $date variable e.g '2013-11-30'. In theory i want to execute something like the below - but it automagically figure out the second value WHERE date >= '2013-11-01' and date <= '2013-11-30': Is there an easy way to do this? Thanks, MoFish Link to comment https://forums.phpfreaks.com/topic/284359-mysql-last-day-of-month/ Share on other sites More sharing options...
Barand Posted November 28, 2013 Share Posted November 28, 2013 $date = '2013-11-01'; $last = date('Y-m-t', strtotime($date)); echo "$date - $last"; // --> 2013-11-01 - 2013-11-30 or you could do WHERE EXTRACT(YEAR_MONTH FROM date) = EXTRACT(YEAR_MONTH FROM '$date') Link to comment https://forums.phpfreaks.com/topic/284359-mysql-last-day-of-month/#findComment-1460513 Share on other sites More sharing options...
MoFish Posted November 28, 2013 Author Share Posted November 28, 2013 Thats exactly what I was looking for. Thank you Barand! Link to comment https://forums.phpfreaks.com/topic/284359-mysql-last-day-of-month/#findComment-1460515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.