Time difference in seconds

date1=$(date +"%H:%M:%S")
date2=$(date +"01:00:54")
diff=$date2-$date1
echo $diff

How to get the time difference in seconds.

i m nt sure why do u wana get second difference like this.if u can tell us in more details we can help u better..
bt i think this below will help u

CAR=`date +%Y%m%d%H%M%S`
CAR2=`date +%Y%m%d%H%M%S`

the above code will give u date in the below format

date +%Y%m%d%H%M%S ; date
20100618095508
Fri Jun 18 09:55:08 2010

so the last 2 digit is ur seconds. u can then do the expr command and get the result of ur difference.

Hi,

diff=$(( $(date -d"$date2" +%s) - $(date -d"$date1" +%s) ))

GNU date again..

I have to run the script at YYYY-MM-DD 01:10:54

./abc.sh PMW 2010-06-17 01:00:54

without cron.

If I execute the script at 00:10:22, i have to make the script sleep till 01:10:54 time and then execute.

So to take the difference of HH:MM:SS and convert to sec and I can make the script sleep for n sec.

date +%Y%m%d%H%M%S 

then i think this will do..

this will give u date in numerical manner and seconds and then minutes before second.
and u can comparison this easily