Date and Time Inputs
Date Format
Check the Shape
Scripts often receive dates from arguments or configuration. A lightweight format check catches obvious mistakes before the value reaches a file name or command.
Program
Play the script to choose a date string and see whether it passes the shape check.
date_format_check.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
run_date="2026-06-01"
if [[ "$run_date" == ????-??-?? ]]; then
status="iso-date"
else
status="bad-date"
fi
echo "$run_date:$status"
#!/usr/bin/env bash
run_date="06/01/2026"
if [[ "$run_date" == ????-??-?? ]]; then
status="iso-date"
else
status="bad-date"
fi
echo "$run_date:$status"
run_date ← 2026-06-01
3run_date="2026-06-01"4if [[ "$run_date" == ????-??-?? ]]; thenvalues this step2026-06-01run_dateif [[ "$run_date" == ????-??-?? ]]; then
3run_date="2026-06-01"4if [[ "$run_date" == ????-??-?? ]]; then5 status="iso-date"values this step2026-06-01run_datestatus ← iso-date
4if [[ "$run_date" == ????-??-?? ]]; then5 status="iso-date"6elsevalues this stepiso-datestatusecho "$run_date:$status"
8fi9echo "$run_date:$status"output2026-06-01:iso-datevalues this step2026-06-01run_dateiso-datestatus
run_date ← 06/01/2026
3run_date="06/01/2026"4if [[ "$run_date" == ????-??-?? ]]; thenvalues this step06/01/2026run_dateif [[ "$run_date" == ????-??-?? ]]; then
3run_date="06/01/2026"4if [[ "$run_date" == ????-??-?? ]]; then5 status="iso-date"values this step06/01/2026run_datestatus ← bad-date
6else7 status="bad-date"8fivalues this stepbad-datestatusecho "$run_date:$status"
8fi9echo "$run_date:$status"output06/01/2026:bad-datevalues this step06/01/2026run_datebad-datestatus
ISO date
`YYYY-MM-DD` is easy to sort and compare as text.
shape check
A shape check catches values that are plainly not in the expected format.
input boundary
Validate date text at the boundary before building paths or commands.