I've got some files and for logging purposes I need to know how many days they are apart as well as potentially some other lengths. So I would like to have a script or application that:

  • Can have two dates entered into it in the following format: DD/MM/YYYY
  • Can optionally also have a time given to it in the format of hh:mm:ss in the 24-hour format
  • Can be told if it should output the time between the two in either: seconds, minutes, hours, days, months or years.
  • Preferably it would be nice if it could be asked to return more than just one amount of time between the two, so even if it outputs it in all those lengths then that is fine.

I am running Ubuntu GNOME 17.04 with GNOME 3.24.1. If there are some commands which can do that that would be fine as well.

  • Could the date input format also be YYYY-MM-DD?
    – Byte Commander
    May 20, 2017 at 20:38
  • @ByteCommander: Preferably not, but if it has to be it has to be.
    – user364819
    May 20, 2017 at 20:43
  • 2
    Does this answer help?
    – Terrance
    May 20, 2017 at 20:48
  • @Terrance That is exactly what I was about to build... +1
    – Byte Commander
    May 20, 2017 at 20:50
  • @Terrance: That does make things a lot simpler... Though obviously my question is still slightly different to that one so some minor alterations will be needed. But than that one of you should be ready to post an answer.
    – user364819
    May 20, 2017 at 21:15

1 Answer 1


The package dateutils is in most distributions and will accomplish this for you.

sudo apt-get install dateutils

The default seems to be in months with short dates.

$ dateutils.ddiff now "01/22/1992" -i "%m/%d/%y"

But the format string can be changed.

$ dateutils.ddiff now "01/22/1992" -i "%m/%d/%y" -f '%S'

As it appears to have built in timezone and locale support it would probably be a safer bet than trying to write a function off of epoch time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy