View Single Post
  #2   Report Post  
Harald Staff
 
Posts: n/a
Default

Two approaches. The first subtracts start from end date, the second use leap
year rules:

Function DaysinYear(LngYear As Long) As Long
DaysinYear = DateSerial(LngYear, 12, 31) - DateSerial(LngYear, 1, 1) + 1
End Function

Function DaysinYear2(LngYear As Long) As Long
DaysinYear2 = 365
If LngYear Mod 4 = 0 Then DaysinYear2 = 366
If LngYear Mod 100 = 0 Then DaysinYear2 = 365
If LngYear Mod 400 = 0 Then DaysinYear2 = 366
End Function

Sub test()
Dim L As Long
For L = 1998 To 2005
MsgBox DaysinYear(L) & vbNewLine & _
DaysinYear2(L), , L
Next
End Sub

HTH. best wishes Harald

"XtraNeed" skrev i melding
...
I need a macro function that allows me to display the number of days (or
hours) in a given year. Any help will be appreciated.