finding the previous day date and creating a file with date

Hi guys,

I had a scenario...
  1. I had to get the previous days date in yyyymmdd format
  2. i had to create a file with Date inthe format yyyymmdd.txt format

both are different

thanks guys in advance..

What's the output from the following command on your system:

date --version

Capture previous days date in yyyymmdd format

previous_day=`TZ=GMT+24 date "+%Y%m%d"`

Create a file with Date in the format yyyymmdd.txt format

touch "$previous_day".txt

Whatch out : the offset may differs depending on the timezone you are in. Have a look at

post #2 of date: illegal option -- d in sun solaris

or

post #6 of Retun yesterday's date on HP-UX

also

perl -e 'print scalar(localtime(time - 86400)), "\n"'
1 Like

Check the FAQ

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html