Home > Blockchain >  Is there any function in sql to extract week?
Is there any function in sql to extract week?

Time:01-20

I want to extract week from datetime, the output I want is 'YY/week', where week is the week of the year (eg '201724' is the 24th week in 2017).

CodePudding user response:

The term "week of the year" is too ambiguous.

  1. The week may start from Sunday, Monday or another weekday
  2. The weeks enumeration in the year may start from 0 or 1
  3. The weeks enumeration in the year may start from the week which includes January, 1 (and hence may be partial) or from first complete week of the year
  4. The last week of the year, if it is partial, may be counted or not

Each DBMS has its own functions (sometimes original, always with original names) that can return the number of the week in the year on a given date. But they can not always take into account the above features.


Important addition provided by enter image description here

  •  Tags:  
  • Related