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:
  dateutils
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
59

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

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

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

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

Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.