Skip to content

Instantly share code, notes, and snippets.

@coreymwamba
Last active May 3, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymwamba/f0b673056a767a3aa77af698a781d0ce to your computer and use it in GitHub Desktop.
Save coreymwamba/f0b673056a767a3aa77af698a781d0ce to your computer and use it in GitHub Desktop.
dateutils' ordinal date format doesn't doesn't work; and everyone is still writing things in Python, so... ordinal dates in Shell
#!/bin/sh
today=$(date +'%A %e %B %Y') # obviously you can modify this line
D=$(echo $today | grep -E -o "(\b(|[0-3])[0-9]\b)")
case $D in
1|21|31)
mod="st"
;;
2|22)
mod="nd"
;;
3|23)
mod="rd"
;;
*)
mod="th"
;;
esac
ordinal="$D$mod"
fulldate=${today/$D/$ordinal}
echo ${fulldate/ / }
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment