Calculate days between dates using dateutils ddiff command

Calculate Days Between Dates using Command

If you want to quickly calculate days between two dates, you can make use of the Linux dateutils ddiff command, lets see some example,

First, make sure that you have dateutils installed on your system, if not you then install it using package manager like apt-get if you are using Linux based OS or brew if using macOS

For Linux
# apt-get install dateutils

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
Preparing to unpack .../dateutils_0.4.5-1.1_arm64.deb ...
Unpacking dateutils (0.4.5-1.1) ...
Setting up dateutils (0.4.5-1.1) ...
For macOS
% brew install dateutils
Example: Calculate days between dates

% ddiff 2022-01-01 2022-03-01

% ddiff 2022-01-01 2022-01-01

% ddiff 2022-01-01 2022-01-02

% ddiff 2022-01-01 2022-01-20

% ddiff 2022-01-01 2022-03-01 -f '%ww %dd'
8w 3d