Monday, 3 March 2014

MySQL query get first and last day of month

# For current month
SELECT DATE_FORMAT(CURDATE(), '%Y-%m-01') AS `First Day Of Current Month`;

SELECT LAST_DAY(CURDATE()) AS `Last Day Of Current Month`;


# For previous month
SELECT DATE_FORMAT(CURDATE() - INTERVAL 1 MONTH, '%Y-%m-01') AS `First Day Of Previous Month`;

SELECT LAST_DAY(CURDATE() - INTERVAL 1 MONTH) AS `Last Day Of Previous Month`;

# For next month
SELECT DATE_FORMAT(CURDATE() + INTERVAL 1 MONTH, '%Y-%m-01') AS `First Day Of Next Month`;

SELECT LAST_DAY(CURDATE() + INTERVAL 1 MONTH) AS `Last Day Of Next Month`; 

No comments:

Post a Comment