MySQL Date and Time Exercises: Get the distinct Mondays from hire_date in employees tables
MySQL Date Time: Exercise-3 with Solution
Write a query to get the distinct Mondays from hire_date in employees tables.
Sample table: employees
Code:
SELECT DISTINCT(STR_TO_DATE
(CONCAT(YEARWEEK(hire_date),'1'),'%x%v%w'))
FROM employees;
Pictorial Presentation of the above query:
Sample Output:
(STR_TO_DATE (CONCAT(YEARWEEK(hire_date),'1'),'%x%v%w')) 1987-06-08T04:00:00.000Z 1987-06-15T04:00:00.000Z 1987-06-22T04:00:00.000Z 1987-06-29T04:00:00.000Z 1987-07-06T04:00:00.000Z 1987-07-13T04:00:00.000Z 1987-07-20T04:00:00.000Z 1987-07-27T04:00:00.000Z 1987-08-03T04:00:00.000Z 1987-08-10T04:00:00.000Z 1987-08-17T04:00:00.000Z 1987-08-24T04:00:00.000Z 1987-08-31T04:00:00.000Z 1987-09-07T04:00:00.000Z 1987-09-14T04:00:00.000Z 1987-09-21T04:00:00.000Z
MySQL Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a query to display the last day of the month (in datetime format) three months before the current month.
Next:Write a query to get the first day of the current year.
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