Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
XtraNeed
 
Posts: n/a
Default Number of days in a year

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   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.



  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

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   Report Post  
Harald Staff
 
Posts: n/a
Default

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   Report Post  
Dana DeLouis
 
Posts: n/a
Default

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i change days in a year to 365 tripjules Excel Discussion (Misc queries) 1 July 29th 05 02:38 AM
interest calcs using 365 days in a year Brad Excel Discussion (Misc queries) 0 June 14th 05 10:08 PM
how do we calculate T-bill Price in 365 days year. ASHAR ZUKA FAROOQI Excel Worksheet Functions 3 May 18th 05 03:08 PM
count number of months year to date coal_miner Excel Worksheet Functions 1 May 4th 05 02:41 PM
days in a year gcape Excel Worksheet Functions 1 April 14th 05 06:33 PM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"