使用 Week No 在 MySql 中获取一周的第一天 [英] Getting first day of the week in MySql using Week No

查看:38
本文介绍了使用 Week No 在 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.

这篇关于使用 Week No 在 MySql 中获取一周的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆