Home > Database > Mysql Tutorial > body text

In MySQL, how can we calculate a date by providing the year, week number and day of the week?

WBOY
Release: 2023-09-13 14:25:02
forward
625 people have browsed it

在 MySQL 中,我们如何通过提供年份、周数和星期几来计算日期?

We can calculate the date as follows -

mysql> SET @year=2017, @week=15, @day=4;
Query OK, 0 rows affected (0.00 sec)
Copy after login

The above query will pass the value "2017" in the "year", "week" and "day" variables respectively ", "15", "4". Then after applying the formula in the query below we can get the date.

mysql> SELECT Str_To_Date( Concat(@year,'-',@week,'-',If(@day=7,0,@day) ), '%Y-%U-%w' ) AS Date;
+--------------+
| Date         |
+--------------+
| 2017-04-13   |
+--------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of In MySQL, how can we calculate a date by providing the year, week number and day of the week?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template