Finding out the date from current date, by going x days back

September 10, 2012 at 22:22:51
Specs: Unix
Hi,
From today's date i need to go back x days and find out which is that date??
Example if today is 11th sep 2012 and x = 10 days then the output i should get it has 01 Sep 2012. Please help me!!

See More: Finding out the date from current date, by going x days back

Report •

#1
September 11, 2012 at 03:44:39
Try this:

x=10;date --date="-$x day"

http://www.cyberciti.biz/tips/linux...


Report •

#2
September 11, 2012 at 09:11:57
paulsep's solution is GNU/Linux based. It's fine if you are running Linux.

For legacy Unix, date arithmetic has been discussed many times on this forum with multiple solutions. Here are two links:

http://www.computing.net/answers/so...
http://www.computing.net/answers/un...

Personally, I think a modern scripting language like perl is a better solution:

#!/bin/ksh

export dback=10
perl -MPOSIX -e 'print strftime("%m-%d-%Y",localtime(time-86400*$ENV{"dback"}))'


Report •
Related Solutions


Ask Question