MySQL Date and Time Exercises: Display the first day of the month three months before the current month
MySQL Date Time: Exercise-1 with Solution
Write a query to display the first day of the month (in datetime format) three months before the current month.
Sample current date : 2014-09-03
Expected result : 2014-06-01
Code:
SELECT date(((PERIOD_ADD
(EXTRACT(YEAR_MONTH
FROM CURDATE()),-3)*100)+1));
Sample Output:
date(((PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE()),-3)*100)+1)) 2017-05-01T04:00:00.000Z
MySQL Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Date and Time functions
Next:Write a query to display the last day of the month (in datetime format) three months before the current month.
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