Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL Date and Time Exercises: Display the last day of the month three months before the current month

MySQL Date Time: Exercise-2 with Solution

Write a query to display the last day of the month (in datetime format) three months before the current month.

Code:

SELECT (SUBDATE(ADDDATE
     (CURDATE(),INTERVAL 1 MONTH),
         INTERVAL DAYOFMONTH(CURDATE())DAY)) 
            AS LastDayOfTheMonth;

Sample Output:

LastDayOfTheMonth
2017-08-31T04:00:00.000Z

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous:Write a query to display the first day of the month (in datetime format) three months before the current month.
Next:Write a query to get the distinct Mondays from hire_date in employees tables.

What is the difficulty level of this exercise?