Code: Select all
# Prompt for date code
$DateCode = Read-Host "Enter Julian date code"
if ($DateCode -notmatch "\b\d{4}\b") {
throw "The date code must be four numbers long."
}
# Set min year to 1980 and the max to current year
$MinYear = 1980
$MaxYear = Get-Date -Format "yyyy"
$Years = $MinYear..$MaxYear
# Extract date and year from $DateCode
$Day = $DateCode.Substring($DateCode.Length - 3)
$Year = $DateCode.Substring(0,1)
if (($Day -gt "365") -or ($Day -eq "000")) {
throw "$Day is an invalid day of the year. It must be a number from 001 to 365."
}
# Display the date excluding the year
$DayMonth = (Get-Date -Day 1 -Month 1).Date.AddDays($day).ToString('MMMM dd')
# List the year based on the first digit of $datecode
$FinalYear = $Years | Select-String -Pattern \w*$Year\b
Write-Host "Your MRE was produced on $DayMonth of one of the following years: $FinalYear"