MySQL Date and Time - Exercises, Practice, Solution
Date and Time functions [21 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
1. Write a MySQL 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
2. Write a MySQL query to display the last day of the month (in datetime format) three months before the current month.
3. Write a MySQL query to get the distinct Mondays from hire_date in employees tables.
Sample table: employees
4. Write a MySQL query to get the first day of the current year.
5. Write a MySQL query to get the last day of the current year.
6. Write a MySQL query to calculate the age in year.
7. Write a MySQL query to get the current date in the following format.
Sample date : 2014-09-04
Output : September 4, 2014
8. Write a MySQL query to get the current date in Thursday September 2014 format.
Thursday September 2014
9. Write a MySQL MySQL query to extract the year from the current date.
10. Write a MySQL query to get the DATE value from a given day (number in N).
Sample days: 730677
Output : 2000-07-11
11. Write a MySQL query to get the first name and hire date from employees table where hire date between '1987-06-01' and '1987-07-30'
Sample table: employees
12. Write a MySQL query to display the current date in the following format.
Sample output: Thursday 4th September 2014 00:00:00
13. Write a MySQL query to display the current date in the following format.
Sample output: 05/09/2014
14. Write a MySQL query to display the current date in the following format.
Sample output: 12:00 AM Sep 5, 2014
15. Write a MySQL query to get the firstname, lastname who joined in the month of June.
Sample table: employees
16. Write a MySQL query to get the years in which more than 10 employees joined.
Sample table: employees
17. Write a MySQL query to get first name of employees who joined in 1987.
Sample table: employees
18. Write a MySQL query to get department name, manager name, and salary of the manager for all managers whose experience is more than 5 years.
Sample table: departments
19. Write a MySQL query to get employee ID, last name, and date of first salary of the employees.
Sample table: employees
20. Write a MySQL query to get first name, hire date and experience of the employees.
Sample table: employees
21. Write a MySQL query to get the department ID, year, and number of employees joined.
Sample table : employees
More to Come !
MySQL Code Editor:
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics