Monday, June 15, 2015

How to get Last Month Date, Current Month Date in mysql

select DATE_FORMAT(NOW(),'%d') as todayDate, DATE_FORMAT(NOW(),'%Y-%m-%d') as printDate, DATE_FORMAT(NOW(),'%Y-%m') as salesGoalMonth, DATE_FORMAT(LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 1 MONTH)),'%Y-%m') as nextMonth, DATE_FORMAT(LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 1 MONTH)),'%d') as lastDateOfMonth, DATE_SUB(CURRENT_DATE, INTERVAL DAYOFMONTH(CURRENT_DATE)-1 DAY) as CurrStartMonth, LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 1 MONTH)) as currEndMonth




SELECT DATE_SUB(DATE_SUB(CURDATE(),INTERVAL (DAY(CURDATE())-1) DAY), INTERVAL 1 MONTH) as lastMonthStart, DATE_SUB(CURDATE(),INTERVAL (DAY(CURDATE())) DAY) as lastMonthEnd