Q. How can I use Windows PowerShell to quickly check whether a particular year is a leap year?

John Savill

April 17, 2008

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. The DateTime library has an isleapyear function to quickly check whether a designated year is a leap year. If the year is a leap year, a true value will return, and if not, a false value will return. The following example uses the DateTime library to check whether 2008 is a leap year:

Usersjohn.SAVILLTECH> [system.datetime]::isleapyear(2008)

The return is:

True

The following command checks whether 2009 is a leap year:

Usersjohn.SAVILLTECH> [system.datetime]::isleapyear(2009)

The return is:

False

To see all the members of system.datetime, pass the class to the Get-Member cmdlet, as follows:

[system.datetime] | get-member

You can use this technique to check members with any PowerShell class or object. It's a great way to determine an object's properties and actions.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like