Last active
March 13, 2026 20:31
-
-
Save StartAutomating/b4877182d79c4e22514fed8f98a8ebbe to your computer and use it in GitHub Desktop.
Gist gotta calculate Friday the 13th
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-Friday13th { | |
| <# | |
| .SYNOPSIS | |
| Get Friday the 13th | |
| .DESCRIPTION | |
| Get the next N Friday the 13ths | |
| .EXAMPLE | |
| Get-Friday13th | |
| #> | |
| [Alias('Friday13th', 'Friday13', 'F13')] | |
| param( | |
| # The number of Friday the 13ths to find (by default, 13) | |
| [ValidateRange(1,1kb)] | |
| [Alias('Number')] | |
| [int] | |
| $N = 13, | |
| # The starting date (by default, today) | |
| [DateTime] | |
| $Date = [DateTime]::Now.Date | |
| ) | |
| $Day = $Date.Date | |
| $FridayThe13th = @() | |
| do { | |
| # Because 5 and 13 are both prime | |
| # Any .DayOfWeek * .Day will be 65 | |
| if ($day.DayOfWeek * $day.Day -eq 65) { | |
| $FridayThe13th += $day | |
| } | |
| $day = $day.AddDays(1) | |
| } while ($FridayThe13th.Count -lt $n) | |
| $FridayThe13th | |
| } | |
| Get-Friday13th |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment