SQL]mysql Week主相関関数(調整日)


  • WEEK(date[,mode])
  • は、州番号/州の開始日が日曜日か月曜日かを返し、0から53または1から182の範囲で
  • を返します.
  • モードパラメータを省略するとdefault week format
  • が使用される.
    Mode | First day of week |	Range	Week 1 is the first week …
    0	Sunday	0-53	with a Sunday in this year
    1	Monday	0-53	with 4 or more days this year
    2	Sunday	1-53	with a Sunday in this year
    3	Monday	1-53	with 4 or more days this year
    4	Sunday	0-53	with 4 or more days this year
    5	Monday	0-53	with a Monday in this year
    6	Sunday	1-53	with 4 or more days this year
    7	Monday	1-53	with a Monday in this year
  • If the week containing January 1 has 4 or more days in the new year, it is week 1.
  • 4日以上の場合、週処理として
  • mysql> SELECT WEEK('2008-02-20');
            -> 7
    mysql> SELECT WEEK('2008-02-20',0);
            -> 7
    mysql> SELECT WEEK('2008-02-20',1);
            -> 8
    mysql> SELECT WEEK('2008-12-31',1);
            -> 53
            
    mysql> SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
            -> 2000, 0
  • YEARWEEK() function:
  • mysql> SELECT YEARWEEK('2000-01-01');
            -> 199952
    mysql> SELECT MID(YEARWEEK('2000-01-01'),5,2);
            -> '52'
  • WEEKDAY(date)
  • Returns the weekday index for date (0 = Monday, 1 = Tuesday, … 6 = Sunday).
  • mysql> SELECT WEEKDAY('2008-02-03 22:23:00');
            -> 6
    mysql> SELECT WEEKDAY('2007-11-06');
            -> 1
    WEEKOFYEAR(date)
  • Returns the calendar week of the date as a number in the range from 1 to 53. WEEKOFYEAR() is a compatibility function that is equivalent to WEEK(date,3).
  • mysql> SELECT WEEKOFYEAR('2008-02-20');
            -> 8
    注意:https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_weekofyear