DELIMITER $$
DROP FUNCTION IF EXISTS `GetLastDayOfMonth` $$
CREATE FUNCTION `GetLastDayOfMonth`
(_MONTH INT ,_YEAR INT ) RETURNS DATE
/* REQUIRE _YEAR FOR PREVENT LEAP YEAR */
BEGIN
DECLARE _TEMP_DATE DATE ;
SET _TEMP_DATE = STR_TO_DATE(CONCAT(1, '/', _MONTH, '/', _YEAR), '%d/%m/%Y');
SET _TEMP_DATE = DATE_ADD(_TEMP_DATE ,INTERVAL 1 MONTH);
SET _TEMP_DATE = DATE_SUB(_TEMP_DATE ,INTERVAL 1 DAY);
RETURN _TEMP_DATE ;
END $$
DELIMITER ;
GetLastDayOfMonthWithDate Code (PHP)
DELIMITER $$
DROP FUNCTION IF EXISTS `GetLastDayOfMonthWithDate` $$
CREATE FUNCTION `GetLastDayOfMonthWithDate`(_DATE DATE) RETURNS DATE
BEGIN
DECLARE _TEMP_DATE DATE ;
SET _TEMP_DATE = STR_TO_DATE(CONCAT(1, '/', MONTH(_DATE), '/', YEAR(_DATE)), '%d/%m/%Y');
SET _TEMP_DATE = DATE_ADD(_TEMP_DATE ,INTERVAL 1 MONTH);
SET _TEMP_DATE = DATE_SUB(_TEMP_DATE ,INTERVAL 1 DAY);
RETURN _TEMP_DATE ;
END $$
DELIMITER ;