26 lines
561 B
Bash
26 lines
561 B
Bash
#!/bin/bash
|
|
if [[ $# -lt 3 ]]; then
|
|
echo "Usage: getdt <from> <to> (format)"
|
|
exit 0
|
|
fi
|
|
|
|
from_date=$1
|
|
to_date=$2
|
|
format="%02d days, %02d:%02d:%02d"
|
|
|
|
if [[ $# -gt 3 ]]; then
|
|
format=$3
|
|
fi
|
|
|
|
target_epoch=$(date -d "$from_date" +%s)
|
|
now_epoch=$(date -d "$to_date" +%s)
|
|
remaining_seconds=$((target_epoch - now_epoch))
|
|
|
|
days=$((remaining_seconds / 86400))
|
|
hours=$(((remaining_seconds % 86400) / 3600))
|
|
minutes=$(((remaining_seconds % 3600) / 60))
|
|
seconds=$((remaining_seconds % 60))
|
|
|
|
printf "%02d days, %02d:%02d:%02d" $days $hours $minutes $seconds
|
|
exit 0
|