使用星期编号在MySql中获取星期几 [英] Getting first day of the week in MySql using Week No
本文介绍了使用星期编号在MySql中获取星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得给定星期几的第一天?
How do I get the first day of a given week whose week number is available?
例如,当我写这篇文章时,我们位于 WEEK 29 .我想编写一个MySQL查询,该查询将使用此 WEEKNO返回 7月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.
这篇关于使用星期编号在MySql中获取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文