Bear with me I am not strong with bash
. I have a date/time as in YYYYMMDDHHMMSS
format such as 20031005000000
in string. I like to add one year to it. I've read man date
but it was a bit hard to interpret what it says although I think I do have basic understanding of -d
and -s
option looking at many examples from WWW.
These are a few of many I read:
- https://stackoverflow.com/questions/46411970/add-x-days-to-a-particular-date-in-bash
- https://stackoverflow.com/questions/25619923/bash-convert-date-to-timestamp
- https://stackoverflow.com/questions/18706823/how-to-increment-a-date-in-a-bash-script
So at the moment, I know how to add one year to current date.
myDatePlusOneYr=$(date -d "+365 days" '+%Y%m%d%H%M%S')
And I can add one year
to date without having time segment (HHMMSS).
myDate="20031005"
date -d "$myDate +365 day"
Mon Oct 4 00:00:00 GMT 2004
However I have not found a way to add one year to a date/time format. When I tried with second option having with time segment, I get following error msg.
date: invalid date `20031005000000 +365 day'
I noticed backtick
at the beginning of date/time and single quote
at the end. I am not sure how to interpret the error msg. I'd appreciate your advice.
Update:
I found an answer for invalid date
: https://stackoverflow.com/questions/4197606/how-to-convert-yyyymmddhhmmss-to-a-date-readable-by-date