Skip to content

Instantly share code, notes, and snippets.

@bahostetterlewis
Created November 4, 2021 19:45
Show Gist options
  • Save bahostetterlewis/4159f166f1a1b86015a685fa64f9e4d6 to your computer and use it in GitHub Desktop.
Save bahostetterlewis/4159f166f1a1b86015a685fa64f9e4d6 to your computer and use it in GitHub Desktop.
simple timediff in bash where a date was generated with date - useful for quick debugging
#!/usr/bin/env bash
datediff() {
d1=$(date -d "$1" +%s)
d2=$(date -d "$2" +%s)
s_t=d1-d2
hours=$((s_t / 3660))
s_t=$((s_t % 3600))
minutes=$((s_t / 60))
seconds=$((s_t % 60))
printf '%02d:%02d:%02d' $hours $minutes $seconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment