Getting week number of date in SQL

前端 未结 6 1457
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 08:26

Is there a way to get the week number of a date with SQL that is database independent?

For example to get the month of a date I use:

SELECT EXTRACT(MONTH         


        
6条回答
  •  我在风中等你
    2021-01-23 09:03

    The only db independent solution I see is to get the number of days between today and Jan 1 of curr. year. Then divide it by 7 and round it up. There is 73 days from Jan 1 till today, which gives 10.43 as week number. The ISO week number is 11.

    Correction: the number of days between last day of the current week and Jan 1 of curr. year. In this case the ISO week is 10, and 68/7 = 10 (rounded).

提交回复
热议问题