I need to add 84 hours to a specific starting UTC date. The start UTC date is the current date but the starting hour is not. The code below works great until the end of the month when it can't convert to the next month or the end of the year when it can't convert years.
#Date variables
export start_year=$(date -u +%Y)
export start_mon=$(date -u +%m)
export start_monc=${start_mon#0} # strip leading 0
export start_day=$(date -u +%d)
export start_dayc=${start_day#0} # strip leading 0
export start_hour=$fhour # -------THIS IS EITHER 6, 12, 18, or 0
And here is where the problems start to appear:
export end_hour=$(( ($start_dayc*24+84)%24 ))
export end_day=$(( $start_dayc+((($start_dayc*24)+84)/24) ))
export end_mon=$(date -u +%m -d '((($start_dayc*24)+84)/24) days')
export end_year=$(date -u +%Y)
The extra variable start_monc
is for calculation since the leading zero creates problems. The ending components need to be broken up like they are. My last resort is creating a series of if statements to change month/year appropriately.
Any suggestions to fix my month/year conversion problem?
Thanks once again for putting up with my questions, great resource on this website.