首页  编辑  

给定某年的某周,得到该周开始和结束日期?

Tags: /MySQL/   Date Created:

方法A:

SET @WEEK_NO = 40;

SET @_BD = '2014-12-29';

SET @_SD = DATE_FORMAT(DATE_ADD(@_BD, INTERVAL 7 * (@WEEK_NO - 1) DAY), '%Y%m%d');

SET @_ED = DATE_FORMAT(DATE_ADD(@_BD, INTERVAL 7 * @WEEK_NO - 1 DAY), '%Y%m%d');

SELECT @_SD, @_ED, DATE_FORMAT(@_SD, '%Y-%v周'), DATE_FORMAT(@_ED, '%Y-%v周')

方法二:

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

Another example:

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

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');

This gives 2010-07-18.