-1

I'm trying to write a script in that need to compute date-1 and date+1 after

reading the Date from variable

echo 2017-09-30 | read YYYY MM DD

how to print next date as 2017-10-01 trying on AIX OS .

This is the piece of code from it

date ()
{
   DAY=$D1
   TODAY=$D1
   DAY1=$D1
   echo $DAY1| read YYYY MM DD
   let DD=DD+1
   DD=`printf %02d $DD`
   if [[ $DD -eq 0 ]] then
   let MM=MM-1
   MM=`printf %02d $MM`
   if [[ $MM -eq 0 ]] then
   let YYYY=YYYY-1
   let MM=12
   let DD=31
   fi
   DD=`cal $MM $YYYY|grep . |fmt -1|tail -1`
  fi
  NEXTDAY=`echo $YYYY-$MM-$DD`
  echo $NEXTDAY
  }
J.RAM
  • 15
  • 6

2 Answers2

0

Tomorrow:

date --date='tomorrow'
date --date='1 day'

Yesterday:

date --date='yesterday'
date --date='1 day ago'

How to save time/date format to the shell variable?

$ NOW=$(date +"%m-%d-%Y")

To display a variable use echo command:

$ echo $NOW
zappee
  • 20,148
  • 14
  • 73
  • 129
0

I answered yesterday at https://stackoverflow.com/a/21283578/3220113

You can have yesterday and tomorrow with the same method, keeping in mind the Daylight Saving Time:

# Tomorrow
echo "$(TZ=GMT-30 date +%Y-%m-%d)
$(TZ=GMT-20 date +%Y-%m-%d)" | grep -v $(date +%Y-%m-%d) | head -1

# Yesterday
echo "$(TZ=GMT+30 date +%Y-%m-%d)
$(TZ=GMT+20 date +%Y-%m-%d)" | grep -v $(date +%Y-%m-%d) | tail -1
Walter A
  • 19,067
  • 2
  • 23
  • 43
  • Its not for tomorrow and yesterday from system's date , its from variable - date varies . – J.RAM Sep 28 '17 at 10:03
  • When you can't install GNU dae or GNU awk, you will need to look for some huge script. I started looking for you, but you have to judge the links which might be suited for you after some changes: https://stackoverflow.com/a/3125174/3220113 or https://decipherinfosys.wordpress.com/2009/07/28/getting-previous-date-in-korn-shell-on-aix-ksh/ or https://groups.google.com/forum/#!topic/comp.unix.shell/s_MJvMbvLDs – Walter A Oct 11 '17 at 21:36