Reputation: 1392
I have this script which is run on the 15th of every month. This script intends to automatically take the last date of the previous month in the format of 'YYYY-MM-DD'. Is there a sql statement to do that?
For example today is 15th January 2017. I will run my script and it will give me a date of 31th December 2016 in the format 2016-12-31.
If it is 15th December 2016, I will get 30th November 2016 in the format 2016-11-30.
Thank you
Upvotes: 0
Views: 1608
Reputation: 11
You can use curdate() - interval 1 month paired with last_day =)
select last_day(curdate() - interval 1 month) as 'last_day_last_month';
Upvotes: 1