Yashida Kim Lee Roger Yashida Kim Lee Roger - 3 years ago 82
MySQL Question

Find Last Day of Last Year in MySQL

I know how to find this (current) year's last day in MySQL.

SELECT LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH)); //It shows this year (2017)'s last day. ==> 2017-12-31


But I do not know how to find LAST YEAR's Last Day.

What queries should I enter to determine last year last day?

For example:

++++This Year++++ | ++++Last Year's Last Day++++

2017 | 2016-12-31
2018 | 2017-12-31
2019 | 2018-12-31
2020 | 2019-12-31


Thanks for your help,
much appreciated.

Answer Source

Just subtract one year:

SELECT DATE_SUB(LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH)), INTERVAL 1 YEAR)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download