Getting week number of date in SQL

前端 未结 6 1458
爱一瞬间的悲伤
爱一瞬间的悲伤 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 08:59

    Try this one : SELECT DATENAME(yy,GETDATE())+RIGHT(DATENAME(wk,GETDATE()),2)

    To understand DATENAME, please follow this link : sqltutorials.blogspot.be/2007/05/sql-datename.html and for the right, suite101.com/article/sql-functions-leftrightsubstrlengthcharindex-a209089 . There are examples to better understand ;-) It will work on MS and other sql servers normally ;-)

提交回复
热议问题