I would like to create a script that tells you how many seconds, minutes and hours have passed since a date (much like the +%s
date
command format). How can I subtract the current date with a specific date?
For example: how many seconds, minutes and hours have passed since 4th of July 1776.
Ubuntu – Seconds, minutes and hours since a date
bashdatescripts
Best Answer
Here's one way to do it:
sets a
time
variable you can use like so:The
+%s
tellsdate
to format toseconds since 1970-01-01 00:00:00 UTC
which helps give us a starting point for doing the math in seconds.Now it can also be added to a script with the same variables.
If you want Years:Days:Hours:Minutes:Seconds since, it would be the following:
Which would give you output like the following:
Hope this helps!