Add datediff useful function.
--- a/.bashrc Tue Jan 14 11:24:18 2014 +0200
+++ b/.bashrc Tue Jan 14 15:12:29 2014 +0200
@@ -176,3 +176,19 @@
. ~/.env.local
fi
+################################################################
+# Useful functions.
+
+datediff() {
+ [[ -n "$1" ]] || { echo first argument is missing; return 1; }
+ [[ -n "$2" ]] || { echo second argument is missing; return 1; }
+ local diff=$(( $(date -d "$2" +%s) - $(date -d "$1" +%s) ))
+ local sec=$(( diff % 60 ))
+ diff=$(( diff / 60 ))
+ local min=$(( diff % 60 ))
+ diff=$(( diff / 60 ))
+ local hour=$(( diff % 24 ))
+ local day=$(( diff / 24 ))
+ echo $day days $hour hours $min minutes $sec seconds
+}
+