C# DateTime IsLeapYear() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.IsLeapYear(year) returns true when a year has 366 days. In a leap year February has 29 days.

The rule is built in: a year is a leap year if it is divisible by 4, except century years, which must also be divisible by 400.

This is a static member of System.DateTime. You call it with the type name, such as DateTime.IsLeapYear(...). DateTime holds a date and time of day with a Kind of Utc, Local, or Unspecified.

Syntax

Call it with the type name and pass a four-digit year.

C#
bool a = DateTime.IsLeapYear(2024);   // true
bool b = DateTime.IsLeapYear(2026);   // false
bool c = DateTime.IsLeapYear(1900);   // false (century rule)
CallWhat it does
DateTime.IsLeapYear(2024)True: divisible by 4.
DateTime.IsLeapYear(1900)False: century year not divisible by 400.
DateTime.IsLeapYear(2000)True: divisible by 400.

The year must be between 1 and 9999. Other values throw ArgumentOutOfRangeException.

Library declarations
C#
public static bool IsLeapYear(int year);

Parameters

ParameterDescription
yearRequired. A year from 1 to 9999.

Return Value

Return ValueDescription
booltrue if the year is a leap year; otherwise false.

C# Examples

Example 1 — Check Three Years

Print the result for 2024, 2026, and 2028.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("2024: " + DateTime.IsLeapYear(2024));
        Console.WriteLine("2026: " + DateTime.IsLeapYear(2026));
        Console.WriteLine("2028: " + DateTime.IsLeapYear(2028));
    }
}

How It Works

  1. String plus bool. C# turns the bool into the text True or False.
  2. 2024 and 2028. Both are divisible by 4, so they are leap years.
  3. 2026. It leaves a remainder of 2 when divided by 4, so it is a normal year.
  4. Four years apart. Leap years usually come every four years.

Example 2 — 1900, 2000, and 2100

Test the exceptions to the divisible-by-4 rule.

C#
using System;

class Program {
    static void Main() {
        foreach (int year in new[] { 1900, 2000, 2100 }) {
            Console.WriteLine(year + " -> " + DateTime.IsLeapYear(year));
        }
    }
}

How It Works

  1. Array of years. The loop tests three century years in a row.
  2. 1900 and 2100. They are divisible by 100 but not by 400, so they are not leap years.
  3. 2000. It is divisible by 400, so it is a leap year.
  4. Arrow text. Each line joins the year, an arrow, and the bool result.

Example 3 — Find the Next Leap Year

Loop from 2026 until IsLeapYear is true, then handle an invalid year.

C#
using System;

class Program {
    static void Main() {
        int year = 2026;
        while (!DateTime.IsLeapYear(year)) year++;
        Console.WriteLine("Next leap year: " + year);
        Console.WriteLine("February days: " + DateTime.DaysInMonth(year, 2));

        try {
            DateTime.IsLeapYear(10000);
        } catch (ArgumentOutOfRangeException) {
            Console.WriteLine("Year must be 1-9999");
        }
    }
}

How It Works

  1. Start at 2026. The loop checks one year at a time.
  2. 2027 is skipped. The loop stops at 2028, the first year where the test is true.
  3. Cross-check. DaysInMonth(2028, 2) returns 29, which agrees with the leap-year result.
  4. Invalid year. 10000 is above the maximum of 9999, so the exception is caught and a message is printed.

Frequently Asked Questions

Yes. 2028 is divisible by 4 and is not a century year.
Century years must be divisible by 400. 1900 is not, so it is not a leap year.
Not safely. It gives the wrong answer for 1900 and 2100. Use DateTime.IsLeapYear.
It throws ArgumentOutOfRangeException. Valid years are 1 to 9999.
366 days. February has 29 days.

Next: Parse()

Convert date text to a DateTime; throws if the text is not a valid date with System.DateTime.

Parse() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful