Get the next N Friday the 13ths
0
Get-Friday13th.ps1
37 lines 826 B view raw
1function Get-Friday13th { 2 <# 3 .SYNOPSIS 4 Get Friday the 13th 5 .DESCRIPTION 6 Get the next N Friday the 13ths 7 .EXAMPLE 8 Get-Friday13th 9 #> 10 [Alias('Friday13th', 'Friday13', 'F13')] 11 param( 12 # The number of Friday the 13ths to find (by default, 13) 13 [ValidateRange(1,1kb)] 14 [Alias('Number')] 15 [int] 16 $N = 13, 17 18 # The starting date (by default, today) 19 [DateTime] 20 $Date = [DateTime]::Now.Date 21 ) 22 23 $Day = $Date.Date 24 25 $FridayThe13th = @() 26 do { 27 # Because 5 and 13 are both prime 28 # Any .DayOfWeek * .Day will be 65 29 if ($day.DayOfWeek * $day.Day -eq 65) { 30 $FridayThe13th += $day 31 } 32 $day = $day.AddDays(1) 33 } while ($FridayThe13th.Count -lt $n) 34 $FridayThe13th 35} 36 37Get-Friday13th