# csh to get difference been start and end time both inputs in hh:mm:ss format

`./script.csh 05:25:00 02:30:50`

should return output in mins

since i am looping through the series recursively how to compare values with new large value . would | bc work in csh ?

It's not clear whether you want the two dates to wrap through days, or you're assuming that they're both in the same day and may be in any order.

This answer assumes the first, i.e. `timediff 23:00:00 01:00:00` should return 2 hours = 120 minutes.

Change `@ s = 86400 + \$s` to `@ s = - \$s` if that should return 22 hours = 79200 minutes.

``````alias timediff 'set t=(\!:*:gs/:/ * 3600 + /:gs/:/ * 60 + /:q);\\
@ s = (\$t) - (\$t); if(\$s < 0) @ s = 86400 + \$s;\\
@ m = \$s / 60;\\
@ H = \$s / 3600 M = \$s % 3600 / 60 S = \$s % 60;\\
echo seconds=\$s minutes=\$m hours=\$H\:\$M\:\$S'

timediff 05:25:00 02:30:50
seconds=75950 minutes=1265 hours=21:5:50
``````

As a script:

``````set t=(\$argv:gs/:/ * 3600 + /:gs/:/ * 60 + /:q)
@ s = (\$t) - (\$t); if(\$s < 0) @ s = 86400 + \$s
@ m = \$s / 60
@ H = \$s / 3600 M = \$s % 3600 / 60 S = \$s % 60
echo seconds=\$s minutes=\$m hours=\$H\:\$M\:\$S
``````

For full difference:

``````perl -e 'for(@ARGV){s/(..):(..):(..)/\$1*3600+\$2*60+\$3/e} \$_=(shift)-(shift); printf"%02d:%02d:%02d\n",\$_/3600,\$_/60%60,\$_%60' 05:25:00 02:30:50
``````

For difference in minutes:

``````perl -e 'for(@ARGV){s/(..):(..):(..)/\$1*3600+\$2*60+\$3/e} \$_=(shift)-(shift); printf"%d\n",\$_/60' 05:25:00 02:30:50
``````

Works in bash, too.

• `% Badly placed (.` – pizdelect Mar 22 at 21:27
• Forgot it has to be on a single line. Edited. – Ole Tange Mar 23 at 8:14