| Comment | SQLServer User-Defined Function
PURPOSE
Return the ISO weeknumber for a given date.
This function is based on a Excel formula developed by Evert van den Heuvel,
and is published at http://www.cpearson.com/excel/weeknum.htm
=1+INT((A1-DATE(YEAR(A1+4-WEEKDAY(A1+6));1;5)+WEEKDAY(DATE(YEAR(A1+4-WEEKDAY(A1+6));1;3)))/7)
where A1 is the datecell, and ; is the separation character.
PARAMETERS
@dt DATETIME Given date
RETURNS INT ISO weeknumber
EXAMPLES
SELECT dbo.fun_date2isoweek(GETDATE())
43
HISTORY
2004-12-07 - Created function
2014-10-21 - Renamed function from fun_weeknr to fun_date2isoweek
2024-02-09 - Changed history table
TAGS
<program>
<description>Return the ISO weeknumber for a given date</description>
<generic>1</generic>
<author>Gerrit Mantel</author>
<created>2004-12-07</created>
<lastmodified>2024-02-09</lastmodified>
</program> |