I’m trying to compute duration in awk having start and end date. Here is my function
function computeDuration(start, end) {
sub(/T/, " ", start);
sub(/T/, " ", end);
print start;
print end;
cmd="date --date=\"$start\" +%s";
cmd | getline startDate;
cmd="date --date=\"$end\" +%s";
cmd | getline endDate;
print startDate;
print endDate;
return endDate-startDate;
}
My output is:
2012-7-16 13:20
2012-7-16 13:30
1342389600
1342389600
Can anybody explain how it is possible that two different dates result in the same +%s result?
It is the the cmd variables that fail.
The $ symbol shouldn’t be there and you need extra quotation marks surrounding the variables