I don't seem to find this anywhere... I have two date/time using YYYYmmddHHMMSS
, like this:
D1=20140603132050
D2=20140604114020
I need to find the difference between them in hours.
- I'm using korn shell;
- I have GNU date;
Any clue?
I don't seem to find this anywhere... I have two date/time using YYYYmmddHHMMSS
, like this:
D1=20140603132050
D2=20140604114020
I need to find the difference between them in hours.
Any clue?
If you have a recent-ish Perl, you can do:
diff_hrs=$(
printf "%s\n" "$D1" "$D2" |
perl -MTime::Piece -e '
($t1, $t2) = map {chomp; Time::Piece->strptime($_, "%Y%m%d%H%M%S")} <>;
print +($t2-$t1)/3600, "\n"
'
)