Linux: Get Number of Days since 1970

Objective: Calculate or get the number of calendar days since 1970 on Linux.

The date command can give us the number of seconds since 1970. Using this result, we can get the number of days by dividing the output by 86400 seconds.

The above output can be interpreted as: Number of days between 1-Jan-1970 and 16-Aug-2018 is 17759 days.

Note that bash only supports integer arithmetic and not floating point by default. We can confirm this by performing a simple calculation as shown below.

The answer is 2 and not 2.5. The number will be rounded down to the nearest whole number.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }