PowerTip: Use PowerShell to identify a leap year

Doctor Scripto

Summary: Use PowerShell and Math to identify a leap year.

Hey, Scripting Guy! Question Is there a way to use PowerShell to identify whether this year is a leap year?

Hey, Scripting Guy! Answer Actually there is! You can use a combination of Get-date to find out the year and the Modulus function in PowerShell.


If the value is zero, the current year is a leap year!

The Doctor

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Joakim Hellström 0

    First of all. There is no leap year if the year can be divided with 100, except if it’s possible to divide by 400. So 1600, 2000 and 2400 are leap year but not 1700, 1800, 1900.Secondly. You can use [datetime]::IsLeapYear

Feedback usabilla icon