How to calculate Calculate number of days in a year?. In reference exists Date.daysInMonth but not in a year.
-
4Can 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 HummJun 13, 2016 at 15:59
-
9You can do Date.isLeapYear(Date.Today().Year()); So you can return 365 or 366 based on true and false.– AlphaBravoJun 13, 2016 at 16:04
1 Answer
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;
}