user6505873
user6505873

Reputation:

How to calculate the difference between two UTC values

I am trying to get the difference (in days) from two UTC values:

export CURRENT_TIME=`date -u %FT%Z`
export START_TIME=`2018-02-26T04:46:20Z`

Can I subtract them directly or do I need to convert them before?

Upvotes: 0

Views: 45

Answers (1)

Diego Torres Milano
Diego Torres Milano

Reputation: 69378

The diff:

diff=$(( $(date --date="$CURRENT_TIME" +%s) - $(date --date="$START_TIME" +%s) ))

also, for CURRENT_TIME I think you mean

export CURRENT_TIME=$(date -u +'%FT%T%Z')

Upvotes: 2

Related Questions