I have the following input.txt file. I need to calculate the time difference of $2 and $3 and print difference in hours.
P1, 2016-05-30 00:11:20, 2016-05-30 04:36:40
P2, 2016-05-30 00:07:20, 2016-05-30 04:32:31
I have the following code, but it looks like the hours is not showing accurate. Please help.
awk -F, '{gsub(/[-:]/," ",$2);gsub(/[-:]/," ",$3);
d2=mktime($3);d1=mktime($2);
print $1","(d2-d1)/3600,"hrs";}' input.txt
I am getting the output like this.
P1,4.42222 hrs
P2,4.41972 hrs
but it should be showing of a difference 4:25:20 hrs 4:25:11 hrs
Thanks in advance