Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between two Timestamps

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hello everyone,

using ksh I need to figure out how many days have passed between a timestamp and the current date of today.

Format of the timestamp is:

YYYYMMDD (e.G. 20200703)

Using

Code:
date +%Y%m%d

will give me the correct format for the current date and at first sight simply substracting both is working fine as long as both are within the same month ...

e.G.

Code:
20200716 - 20200703

Problem is obvious:

Code:
20200801 - 20200703

Any ideas how to solve this ?

Best Regards,
Thomas
 
Hi

Such math is usually done with Unix times :
Code:
date='20200703'
echo $(( ($( date +'%s' ) - $( date -d "$date" +'%s' )) / 24 / 60 / 60 ))


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top