使用 Week No 在 MySql 中获取一周的第一天

2021-11-20 00:00:00 sql mysql

如何获得周数可用的给定周的第一天?

How do I get the first day of a given week whose week number is available?

例如,当我写这篇文章时,我们在 WEEK 29.我想编写一个 MySQL 查询,该查询将使用这个 WEEKNO 返回 Sunday 18 29 作为唯一可用的参数.

For example as I write this post we are at WEEK 29.I would like to write a MySQL query that will return Sunday 18 July using this WEEKNO 29 as the only available parameter.

推荐答案

您可以使用:

SELECT STR_TO_DATE('201003 Monday', '%X%V %W');

这将为您提供 2010 年第 3 周的星期一日期,即 2010-01-18.

This would give you the Monday date of week 3 of 2010, which would be 2010-01-18.

另一个例子:

 SELECT STR_TO_DATE('201052 Sunday', '%X%V %W');

将为您提供 2010 年第 52 周的星期日日期,即 2010-12-26.

Would give you the Sunday date of week 52 of 2010, which would be 2010-12-26.

最后,使用您的原始示例:

And finally, using your original example:

SELECT STR_TO_DATE('201029 Sunday', '%X%V %W');

这给出了 2010-07-18.

This gives 2010-07-18.

相关文章