VBA Convert date to week number

前端 未结 6 414
渐次进展
渐次进展 2021-01-12 12:01

In VBA I want to convert a date as 03/11/2017(DD/MM/YYYY) into the week number for that date.

Until now I have the following code:

   \'geting the d         


        
6条回答
  •  广开言路
    2021-01-12 12:28

    Be carefull when it comes to week numbers as there are different definitions around. The Excel definition differs from the ISO definition. To get the ISO weeknumber use (copied From http://www.rondebruin.nl/win/s8/win001.htm)

    Public Function IsoWeekNumber(d As Date) As Integer
        Dim d2 As Long
        d2 = DateSerial(Year(d - Weekday(d - 1) + 4), 1, 3)
        IsoWeekNumber = Int((d - d2 + Weekday(d2) + 5) / 7)
    End Function
    

提交回复
热议问题