How to add days to date and get new date on Linux

On Linux, you can use the command line tool “date” to add days to a date and get a new date.

Here’s an example of how you can add 30 days to the current date and get the new date:

date --date='30 days' +%Y-%m-%d

This command will add 30 days to the current date and returns the new date in the format YYYY-MM-DD.

You can also add days to a specific date by replacing “30 days” with the specific date, for example:

date --date='2022-10-15 + 30 days' +%Y-%m-%d

This command will add 30 days to the date 2022-10-15 and returns the new date in the format YYYY-MM-DD.

You can also use the “+X days” format, where X is the number of days you want to add to the date, for example:

date --date='+30 days' +%Y-%m-%d

This command will add 30 days to the current date and returns the new date in the format YYYY-MM-DD.

You can also add weeks, months and years to a date by using the “+X weeks”, “+X months” and “+X years” format.

date --date='+6 months' +%Y-%m-%d

This command will add 6 months to the current date and returns the new date in the format YYYY-MM-DD.

It’s important to note that, the date command may vary depending on the Linux distribution, some distributions have different versions of date command or use different command like ‘dateutils’, it’s recommended to check the date command documentation for your specific distribution.

(chipedge.com)

Leave a Comment