2

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

  • 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 '16 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 '16 at 16:04
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;
}
  • @AdrianLarson Go ahead. – AlphaBravo Jun 13 '16 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.