Home » Questions » Computers [ Ask a new question ]

how to add a day to date in bash?

how to add a day to date in bash?

For example, I have date: 4 August 1993 and I want to add 348 days to it, how can I do it in bash?

Asked by: Guest | Views: 81
Total answers/comments: 2
Guest [Entry]

"Just use the date command with -d option:

$ date -d ""1983-08-04 348 days""
Tue Jul 17 00:00:00 BST 1984

You can change the output format if you want:

$ date -d ""1983-08-04 2 days"" +%Y-%m-%d
1983-08-06"
Guest [Entry]

"Here is a little more complex usage of this:

for i in `seq 1 5`;
do;
date -d ""2014-02-01 $i days"" +%Y-%m-%d;
done;

or with pipes:

seq 1 5 | xargs -I {} date -d ""2014-02-01 {} days"" +%Y-%m-%d"