#!/bin/bash OLD="2006-12-10 12:00" NEW="2006-12-10 13:00" TIME="$(((`date +%s -d "${NEW}"` - `date +%s -d "${OLD}"`)))" #SHOW SEC echo "$TIME secs" # if over 48 houers show as days if [[ "$(($TIME / 60 / 60 ))" -ge "48" ]] then #show Days SPLIT=$(bc << EOF scale=1 ($TIME / 60 / 60 / 24) EOF ) echo "$SPLIT Day(s) between old and new dato" # if under 2 days.. show as houers elif [[ "$(($TIME /60))" -ge "60" ]] && [[ "$(($TIME / 60/ 60))" -le "48" ]] then #show Houers SPLIT=$(bc << EOF scale = 2 ($TIME / 60 / 60) EOF ) echo "$SPLIT Houer(s) between old and new dato" # if less than 1 houer show as minutes elif [[ "$(($TIME /60))" -lt "60" ]] then #show minutes SPLIT=$(bc << EOF scale=1 ($TIME / 60) EOF ) echo "$SPLIT Minute(s) between old and new Dato" fi #################################### OUTPUT WITH SET-X ################################### + OLD='2006-12-10 12:00' + NEW='2006-12-10 13:00' ++ date +%s -d '2006-12-10 13:00' ++ date +%s -d '2006-12-10 12:00' + TIME=3600 + echo '3600 secs' 3600 secs + [[ 1 -ge 48 ]] + [[ 60 -ge 60 ]] + [[ 1 -le 48 ]] ++ bc (standard_in) 3: illegal character: O (standard_in) 3: parse error + SPLIT=1.00 + echo '1.00 Houer(s) between old and new dato' 1.00 Houer(s) between old and new dato ########################################### without set-x ############################################ 3600 secs (standard_in) 3: illegal character: O (standard_in) 3: parse error 1.00 Houer(s) between old and new dato