Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
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. |
#2
![]() |
|||
|
|||
![]()
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. |
#3
![]() |
|||
|
|||
![]()
dim myYear as long
dim daysinyear as long myyear = 2005 if month(dateserial(myYear,2,29))= 2 then daysinyear = 366 else daysinyear = 365 end if XtraNeed wrote: 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. -- Dave Peterson |
#4
![]() |
|||
|
|||
![]()
Ah, month. Another just for the fun of it:
Function DaysinYear3(LngYear As Long) As Long DaysinYear3 = 368 - Month(DateSerial(LngYear, 2, 29)) End Function Best wishes Harald "Dave Peterson" skrev i melding ... dim myYear as long dim daysinyear as long myyear = 2005 if month(dateserial(myYear,2,29))= 2 then daysinyear = 366 else daysinyear = 365 end if XtraNeed wrote: 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. -- Dave Peterson |
#5
![]() |
|||
|
|||
![]()
Just another method:
Function DaysInYear(Year) As Long DaysInYear = Format(DateSerial(Year, 12, 31), "y") End Function -- Dana DeLouis Win XP & Office 2003 "XtraNeed" wrote in message ... 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how do i change days in a year to 365 | Excel Discussion (Misc queries) | |||
interest calcs using 365 days in a year | Excel Discussion (Misc queries) | |||
how do we calculate T-bill Price in 365 days year. | Excel Worksheet Functions | |||
count number of months year to date | Excel Worksheet Functions | |||
days in a year | Excel Worksheet Functions |