Two digit week numbers in VB
Hi everyone.
I am currently using the following code to obtain two digit week numbers in excel. Is there an easier or cleaner way of doing it? If Len(DatePart("WW", Now())) < 2 Then _ maxDate = DatePart("YYYY", Now()) & " 0" & _ DatePart("WW", Now()) _ Else maxDate = DatePart("YYYY", Now()) & " " & _ DatePart("WW", Now()) _ Thanks, John |
Two digit week numbers in VB
John
?format(DatePart("WW", Now()),"00") NickHK "John Ortt" wrote in message ... Hi everyone. I am currently using the following code to obtain two digit week numbers in excel. Is there an easier or cleaner way of doing it? If Len(DatePart("WW", Now())) < 2 Then _ maxDate = DatePart("YYYY", Now()) & " 0" & _ DatePart("WW", Now()) _ Else maxDate = DatePart("YYYY", Now()) & " " & _ DatePart("WW", Now()) _ Thanks, John |
Two digit week numbers in VB
Public Function IsoWeekNum(d1 As Date) As Integer
Dim d2 As Long d2 = DateSerial(Year(d1 - Weekday(d1 - 1) + 4), 1, 3) IsoWeekNum = Int((d1 - d2 + Weekday(d2) + 5) / 7) End Function Code will be: wNum = IsoWeekNum(Now()) WeekNum = wNum if wNum < 10 then WeekNum = "0" & wNum John Ortt wrote: Hi everyone. I am currently using the following code to obtain two digit week numbers in excel. Is there an easier or cleaner way of doing it? If Len(DatePart("WW", Now())) < 2 Then _ maxDate = DatePart("YYYY", Now()) & " 0" & _ DatePart("WW", Now()) _ Else maxDate = DatePart("YYYY", Now()) & " " & _ DatePart("WW", Now()) _ Thanks, John |
Two digit week numbers in VB
Thanks Nick,
That did the trick "NickHK" wrote in message ... John ?format(DatePart("WW", Now()),"00") NickHK |
All times are GMT +1. The time now is 04:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com