Home >Database >Mysql Tutorial >How to Find the First Day of a Week Using its Week Number in MySQL?
Database queries often require the efficient retrieval of specific dates. One common scenario is determining the first day of a particular week given its week number. This article explores how to achieve this using MySQL's powerful date manipulation functions.
To obtain the first day of a given week, you can utilize the following MySQL query:
SELECT DATE_SUB(DATE_ADD(DATE('2022-07-18'), INTERVAL 1 - DAYOFWEEK(DATE('2022-07-18')) DAY), INTERVAL WEEKDAY(DATE('2022-07-18')) - 1 DAY) AS Start_Day;
In this query:
Using the provided sample date of '2022-07-18' (Tuesday), the query would return the following output:
Start_Day ---------- 2022-07-18
This result confirms that the first day of the week for the given week number (29) is indeed Sunday, July 18, 2022.
The above is the detailed content of How to Find the First Day of a Week Using its Week Number in MySQL?. For more information, please follow other related articles on the PHP Chinese website!