问题描述
我正在尝试使用YEARWEEK函数,以将周日视为一周的第一天.
I'm trying to get the YEARWEEK function to see Sunday as the 1st day of the week.
示例日期为:2009年3月1日,星期日
An example date is: Sunday 1st Mar 2009
这是我的SQL
SELECT YEARWEEK('2009-03-01')
结果是
-> 200909
第9周是哪个星期.我认为这是第9周,因为它将星期日视为上一周的最后一天.
Which is week 9. I believe it is telling me this is week 9 because it sees the sunday as the last day of the previous week.
我如何获取此功能以将星期日视为一周的第一天并因此返回至第十周?
How would I get this function to see sunday as the 1st day of the week and therefore return as week 10?
推荐答案
根据 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_yearweek ,YEARWEEK
具有可选第二个参数控制了这一点. YEARWEEK('2009-03-01', 0)
应该做您想要的(但是请参阅该页面上WEEK
下的可能值表).
According to http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_yearweek, YEARWEEK
has an optional second argument which controls this. YEARWEEK('2009-03-01', 0)
should do what you want (but see the table of possible values under WEEK
on that page).
这篇关于如何使YEARWEEK()将星期日视为一周的开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!