Skip navigation

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

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:

Users\john.SAVILLTECH> \[system.datetime\]::isleapyear(2008)

The return is:

True

The following command checks whether 2009 is a leap year:

Users\john.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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish