pdd - Tool to find Date and Time Difference in Linux Command Line
Abstract: $ pdd -t 00$ pdd 1 1 1 --add
In some occasions where you want to check by how many years someone older than you, how old you are (in days, years or months), the countdown to an event or the next flash sale. There is a python-based command line application known as pdd which enables you to calculate date and time differences. Now, there's no go online and search for websites for date and time calculations. In this article, we'll give you more insight into "pdd" tool and teach you how to use it.
Installing pddTo install pdd in Ubuntu/Debian, we first have to install the dependencies - pdd requires Python 3.5
or newer and the dateutil
module.
To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
Date & Time in Python (Printing and Calculating Date and Time) (Video 53)$ sudo apt-get install python3-dateutil
or using pip3
$ sudo pip3 install dateutil
Now, we'll install pdd from the github repository by entering these commands:
$ git clone https://github.com/jarun/pdd.git $ cd pdd/ $ sudo make install
This will install pdd to the /usr/local/bin/. To remove, run:
$ sudo make uninstall
Alternatively, and for other Linux distros, you can install and run pdd from the source directory using these commands:
$ git clone https://github.com/jarun/pdd.git $ cd pdd/ # chmod +x pdd # cp ppd /bin/ppd $ pddUsing pdd
pdd seems a bit difficult to use in the start, especially with the white spaces, but it's pretty easy to learn too. Here's the basic syntax with available options.
pdd [arguments] [keywords]
The positional keywords are:
diff/add/subtract from today or now
and optional arguments are:
-h, --help -> show this help message and exit -d [dd mmm yyyy | d m y] -> calculate date difference -t [hh:mm:ss | h:m:s] -> calculate time difference --add -> add to date (/today) or time (/now) --sub -> subtract from date (/today) or time (/now)
Here are a few operational instructions to note.
- Times are displayed in 24-hr format.
- Months can be specified with their respective number (e.g. Jan = 1, Apr = 4, etc.).
- The absolute difference is shown.
- There is no particular order of argument.
- The end date not included in date difference calculations.
- Hours, minutes or seconds can be omitted. Partial inputs are recognized as mm:ss or ss.
Here are some examples of pdd. Entering only pdd gives you the current date, time and timezone
$ pdd Tue 25 Jul 2017 01:07:12 GMT
Calculate date difference:
$ pdd -d 4 jul 1766 4 7 2017 251y 0m 0d 91676d
Calculate time difference:
$ pdd -t 6:45:50 6:17 06:39:33 23973s
$ pdd -t 45:50 6:17:30 05:31:40 19900s
Calculate time difference with roll-over:
$pdd -t 6:59:61 06:00:01 01:00:00 3600s
Calculate date difference from today:
$ pdd 1 Jan 2018 0y 5m 7d 160d
Calculate time difference from now:
$ pdd 1:17:50 00:01:00 60s
Add a duration (in days, months, or years) to an existing date:
$ pdd -d 25 6 2017 7 6 0 --add 01 Jan 2018
In the above example, we added 7 days, 6 months, and 0 years to 25th June, 2017.
Add a timeslice:
$ pdd -t 00:45:00 1:00:1 --add 01:45:01 00:15:01 901s
In the above example, we added 1 hour, 0 minutes and 1 second to 00:45:00
Add a duration (1 day, 1 month, 1 year) to today:
$ pdd 1 1 1 --add 26 Aug 2018
Add a timeslice (1 hour, 2 minutes, 3 seconds) to now:
pdd 1:2:3 --add 02:30:15 00:26:09 1569s
Subtract a duration (16 days, 8 months and 16 years) from 25 July, 2017:
$ pdd -d 25 07 2017 16 8 16 --sub 09 Nov 2000
Subtract a timeslice (30 sec) from noon:
$ pdd -t 12:00:00 30 --sub 11:59:30
Subtract a duration (3 days, 2 months and 1 year) from today:
$ pdd 3 2 1 --sub 22 May 2016
Subtract a timeslice (0 seconds, 1 minute, and 30 seconds) from now:
$ pdd 0:1:30 --sub 01:42:09
In this article, we learned about the pdd utility, how to install it and finally how to use it to calculate date and time. With more practice, you'll eventually be able to use the utility with very little need to resort to other methods for calculating time.