How to add days to specified date
Hi All,
My requirement is to add no.of days to specified date as shown below. Please let me know how to convert the string to date format as "Tue 15 May 2012 17:22 IST" or similar and after conversion how to add no.of days to the date. For Eg: rechstring="201205151722" adddays=5 output:201205201722 |
Quote:
|
Another good starting point is the info utility: the date info pages are rich of examples and exahustive explanations. To dig into details about your question, see:
Code:
info --index-search="Relative items in date strings" date |
Just to be clear on it first, what environment are we talking about here? The shell, or another programming language?
Assuming the shell, as mentioned, the gnu version of the date command used by Linux is capable of directly modifying an input date, using the -d option. The only caveat is that the original date string mus be in a format it can understand first, such as the ISO standard "YYYY-MM-DD" (see info date -> date input formats). Another option is to convert the date into epoch seconds, use simple arithmetic to add the appropriate number of seconds to it (e.g. +432000, for 5 days), and then reconvert it back into the desired format. But again, you'll probably have to use date or a similar program to convert to and from epoch. |
As David pointed out, you just need to go through manual of date command (see here).
In the meantime, following would work for you: Code:
~$ date +%Y%m%d%H%M |
All times are GMT -5. The time now is 11:03 AM. |