sql >> Databasteknik >  >> RDS >> Oracle

Hur man extraherar veckonummer i sql

Efter att ha konverterat din varchar2 datum till ett sant date datatyp och konvertera sedan tillbaka till varchar2 med önskad mask:

to_char(to_date('01/02/2012','MM/DD/YYYY'),'WW')

Om du vill ha veckonummer i ett number datatyp kan du slå in satsen i to_number() :

to_number(to_char(to_date('01/02/2012','MM/DD/YYYY'),'WW'))

Du har dock flera alternativ för veckonummer att överväga:

WW  Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
W   Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IW  Week of year (1-52 or 1-53) based on the ISO standard.


  1. SQL - Kombinera flera liknande frågor

  2. MySQL strippar icke-numeriska tecken för att jämföra

  3. MariaDB JSON_UNQUOTE() Förklarad

  4. MySQL Group By och Summa totalt värde för annan kolumn