I can do that in php with the following code:
$dt1 = '2011-11-11 11:11:11';
$t1 = strtotime($dt1);
$dt2 = date('Y-m-d H:00:00');
$t2 = strtotime($dt2);
$tDiff = $t2 - $t1;
$hDiff = round($tDiff/3600);
$hDiff
will give me the result in hours.
How do I implement the above in bash shell?
You could use
date
command to achieve this.man date
will provide you with more details. A bash script could be something on these lines (seems to work fine on Ubuntu 10.04 bash 4.1.5):Hope this helps!