Consulting

Results 1 to 3 of 3

Thread: Solved: How many days in year

  1. #1
    VBAX Regular
    Joined
    Aug 2005
    Posts
    77
    Location

    Solved: How many days in year

    Hei.

    How to calculate how many days is in the year. 365 or 366 ?!

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    [VBA]
    Private Function GiveNumDaysInYear(Year As Long) As Integer
    GiveNumDaysInYear = IIf(Year Mod 4, 365, 366)
    End Function
    [/VBA]

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Cass,

    Tommy's solution isn't quite complete as it doesn't cater for 'century years'. This should give the right answer for all years[vba]Function DaysInYear(Year As Long) As Long
    DaysInYear = 365 - (Year Mod 4 = 0) + (Year Mod 100 = 0) - (Year Mod 400 = 0)
    End Function[/vba]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •