I'm trying to figure out how to detract days from a date, lets say I set the current date
set $date
How can I detract days from it and get the date of that period?
for example 27jul2012
detracting 5 becomes 22jul2012
You can use date
to calculate the difference, e.g.
date -d "27jul2012 - 5 days" +%d%b%Y
Convert it to seconds first, subtract the number of seconds in five days and convert back:
date --date=@$(($(date --date='27 Jul 2012' +'%s') - $((5 * 24 * 3600)) )) +%x
you can use the date utility to convert your date in second. see at Bash script compare two date variables.
and you can also perform several different kind of addition and subtraction from the current date. Have a look there : http://linuxconfig.org/addition-and-subtraction-arithmetics-with-linux-date-command
A slightly shorter version:
date --date="@$(expr $(date +%s) - 432000)"
Where 432000 is the number of seconds in 5 days.