Created
November 4, 2021 19:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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