Share via


PowerShell: Identify the leap year

PowerShell: Identify the leap year

Requirement:

How to get Leap Year details using Powershell?

Logic:

Any year divided by 4 returns decimal is not a leap year

Can we apply this logic Using PowerShell?

Indeed - But it's tedious way to do. We need to get the year divide it by 4 and check the returned data type. It's possible. But we can use .NET method for this

Code:

 
@(1983..2014).ForEach({"Is
 this Leap Year {0}: {1}" -f $_ , [datetime]::IsLeapYear($_) | ? {$_ -match 'True'}}) 

Result