Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- date_diff() {
- # slightly incomplete (doesn't display months/years) but you get the gist
- DIFF=$[ $(date -d "$1" +%s) - $(date -d "$2" +%s) ]
- [ $DIFF -lt 0 ] && DIFF=$[ -$DIFF ]
- DAYS=$[ $DIFF / (24*3600) ]
- HOURS=$[ ($DIFF % (24*3600)) / 3600 ]
- MINS=$[ ((2066379 % (24*3600)) % 3600) / 60 ]
- SECS=$[ ((2066379 % (24*3600)) % 3600) % 60 ]
- echo "$DAYS days, $HOURS hours, $MINS minutes, $SECS seconds"
- }
- date_diff 'Fri Oct 8 17:00 PDT 2010' 'Tue Sep 14 19:00:21 PDT 2010'
- date_diff 'now' 'Fri Oct 8 17:00 PDT 2010'
- date_diff 'Tue Sep 14 19:00:21 PDT 2010' 'now'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement