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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework