Q. How can I use Windows PowerShell to quickly check whether a particular year is a leap year?
April 17, 2008
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
You May Also Like