2

How to calculate Calculate number of days in a year?. In reference exists Date.daysInMonth but not in a year.

2
  • 4
    Can you add some more detail of your use case - is this just the number of calendar days in 1 year or number of working days? After all years are more fixed at 365 or 366 days? How to Ask
    – Dave Humm
    Jun 13, 2016 at 15:59
  • 9
    You can do Date.isLeapYear(Date.Today().Year()); So you can return 365 or 366 based on true and false.
    – AlphaBravo
    Jun 13, 2016 at 16:04

1 Answer 1

4

You can do Date.isLeapYear(someYear); and return 365 or 366 based on if it returns true or false.

public static Integer daysInYear() { return daysInYear(Date.today()); }
public static Integer daysInYear(Date input)
{
    return Date.isLeapYear(input.year()) ? 366 : 365;
}
1
  • @AdrianLarson Go ahead.
    – AlphaBravo
    Jun 13, 2016 at 17:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .