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: 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:

Pictorial: Query to get the distinct Mondays from hire_date in employees tables

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?