Last active
August 21, 2024 14:58
-
-
Save stranger777/d84a6b85c82adbc35cb57430cd5479ae to your computer and use it in GitHub Desktop.
Simplest calculator two dates difference. By default in days
This file contains hidden or 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
#!/bin/bash | |
#Simplest calculator two dates difference. By default in days | |
# Usage: | |
# ./datediff.sh first_date second_date [-(s|m|h|d) | --(seconds|minutes|hours|days)] | |
first_date=$(date -d "$1" "+%s") | |
second_date=$(date -d "$2" "+%s") | |
case "$3" in | |
"--seconds" | "-s") period=1;; | |
"--minutes" | "-m") period=60;; | |
"--hours" | "-h") period=$((60*60));; | |
"--days" | "-d" | "") period=$((60*60*24));; | |
esac | |
datediff=$(( ($first_date - $second_date)/($period) )) | |
echo $datediff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment