Blog

Article Tags

Halloween Countdown Script

By William Jeffrey Rankin, Fri June 28 2024

A little diversion: a Halloween countdown script written in PowerShell (and Rexx).

Usage and Sample Output

jeffr@Europa: ~/Halloween $ powershell ./halloween.ps1
There are only 125 days until Halloween! This year, it falls on a Thursday.

The Code

# halloween - Display the number of days until Halloween and the day on which it falls

# $Author: jeffr $
# $Date: 2024-06-28 15:57:30 -0400 (Fri, 28 Jun 2024) $
# $Revision: 4 $

$c_date = Get-Date -Format 'MM/dd/yyyy'
$c_year = ($c_date.Split('/'))[2]
$h_date = "10/31/$c_year"

$days   = (((New-TimeSpan -Start $c_date -End $h_date).ToString()).Split('.'))[0]
$day    = (Get-Date $h_date).DayOfWeek

Write-Host "There are only $days days until Halloween! This year, it falls on a $day."

The Same in Rexx

/* halloween - Display the number of days until Halloween and the day on which it falls

$Author: jeffr $
$Date: 2024-07-07 17:42:05 -0400 (Sun, 07 Jul 2024) $
$Revision: 5 $
*/

c_date = DATE('B')
parse value DATE('N', c_date, 'B') with day ' ' month ' ' year
h = '31 Oct' year
h_date = DATE('B', h)

days = h_date - c_date
day = DATE('W', h, 'B')

say 'There are only' days 'days until Halloween! This year, it falls on a' day'.'