Returns true if the specified \a year is a leap-year in the Gregorian calendar (contains 29days in February). <span align="right" style="background-color:9999FF"><strong>Open Office: ISLEAPYEAR</strong></span>

View versions (1)

Interface

#include <codecogs/units/date/isleapyear.h>

using namespace Units::Date;

Returns a boolean (true/false) to indicate if the specified Year is a within a leap year.

In the Gregorian* calendar a typical year has 365 97/400 days = 365.2425 days. Therefore there are 97 leap years in every 400 years.

To facilitate this a leap year occurs when:

  • the year is divisible by 4 but not divisible by 100, or
  • the year is divisible by 400

So, 1700, 1800, 1900, 2100, 2200 are not leap years, but 1600, 2000, and 2400 are leap years.

(*) The Gregorian calendar was first introduced in 1582 by predominantly Catholic countries. This change occurred on the 4th October 1582, with 10 days being lost, such that 15th October was the next day. Today the vast majority of countries operate use the Gregorian calendar, the main exceptions being the Greek and Russian Orthodox churches, which still use the earlier Julian calendar. Note this is not to be confused with the Julian date system standard that CodeCogs has adopted which defined any date as the number of days from 24 November 4714 BC in the Gregorian calendar (or the number of days from 1 January 4713BC in the Julian Calendar)

Example 1

To output the number of days in each month of 1974

#include <stdio.h>
#include <codecogs/units/date/isleapyear.h>
  
int main()
{
  for(int i=1900; i<2010; i++)
    printf("\n%d %s a leap year", i, Units::Date::isLeapYear(i) ? "is":"is not");
  return 0;
}

A leap year in the Julian calendar is simply any year divisible by 4, so we see no reasons to supply this as a distinct function. But here's the code (!!):

bool isJulianLeapYear= !(Year%4);
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

year
Result