Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Created January 28, 2021 02: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 justanotherdot/8b130ad303b7bec2ff7cc405db3fdbe1 to your computer and use it in GitHub Desktop.
Save justanotherdot/8b130ad303b7bec2ff7cc405db3fdbe1 to your computer and use it in GitHub Desktop.
Compare twwo dates.
: {d1:=1}
: {d2:=2}
: {op:?"provide an operator for comparison"}
lhs=date -j -f "%F" "$d1" +%s 2>/dev/null
rhs=date -j -f "%F" "$d2" +%s 2>/dev/null
case $op in
"eq")
[ lhs -eq rhs ] ;;
"ge")
[ lhs -ge rhs ] ;;
"le")
[ lhs -le rhs ] ;;
"gt")
[ lhs -gt rhs ] ;;
"lt")
[ lhs -lt rhs ] ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment