Alex Rivera | Logout

Get the first and last date of next month in MySQL

Asked 2010-06-09T20:59:10.500
31

How can I get the first and last day of next month to be used in the where clause?

Edit
Report

1 Answer

2

As @DanielVassallo explained it, retrieving the last day of next month is easy:

SELECT LAST_DAY(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH));

To retrieve the first day, you could first define a custom FIRST_DAY function (unfortunately MySQL does not provide any):

DELIMITER ;;
CREATE FUNCTION FIRST_DAY(day DATE)
RETURNS DATE DETERMINISTIC
BEGIN
  RETURN ADDDATE(LAST_DAY(SUBDATE(day, INTERVAL 1 MONTH)), 1);
END;;
DELIMITER ;

And then you could do:

SELECT FIRST_DAY(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH));
answered 2012-06-22T14:58:57.210

Your Answer