Next day of the user entered date - date +1 day

24,611

With relatively recent versions of ksh93:

$ printf "%(%Y/%m/%d)T\n" "2014/06/20 +1 day"
2014/06/21

Or:

$ printf "%(%Y/%m/%d)T\n" "2014/06/20 next day"
2014/06/21  
$ printf "%(%Y/%m/%d)T\n" "2014/06/20 tomorrow"
2014/06/21
Share:
24,611

Related videos on Youtube

cm60
Author by

cm60

Updated on September 18, 2022

Comments

  • cm60
    cm60 over 1 year

    I am new to scripting. I need a script in the AIX environment to get the next days date based on the date entered by the user.

    After hard time browsing for this, I got a piece of code which does the reverse of the goal which i had to achieve. It gets me one day before (yesterday) the date entered by the user.

    The code is this

    #!/bin/ksh
    echo "Enter the date (YYYY/MM/DD):"
    read date
    YEAR=`echo $date | cut -d"/" -f1`
    MONTH=`echo $date | cut -d"/" -f2`
    DAY=`echo $date | cut -d"/" -f3`
    DAY=`expr "$DAY" - 1`
    case "$DAY" in
    0)
    MONTH=`expr "$MONTH" - 1`
    case "$MONTH" in
    0)
    MONTH=12
    YEAR=`expr "$YEAR" - 1`
    ;;
    esac
    DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`
    esac
    echo "Yesterday's Date is $YEAR/$MONTH/$DAY"
    

    Can someone please help achieve to get the next day of the user entered date.

    Desired Output:

    Enter the date (YYYY/MM/DD): 2013/09/30
    
    Tomorrow's Date is 2013/10/1
    
  • Angel Todorov
    Angel Todorov over 10 years
    No input validation is performed here, so if the user enters an invalid date format, perl will complain.
  • Angel Todorov
    Angel Todorov over 10 years
    Did you check? I believe that Time::Piece and Time::Seconds are core Perl modules.
  • cm60
    cm60 over 10 years
    Yes. I had tried it earlier I was getting perl modules not found errors. I do not have admin access for that machine to install the perl modules.
  • cm60
    cm60 over 10 years
    :Can you please help me to edit the above piece of code.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 10 years
    Not on AIX you can't. This would work on Linux.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 10 years
    Not on AIX you can't. This would work on Linux.
  • Marek Zakrzewski
    Marek Zakrzewski over 10 years
    Oh I totally missed AIX.It would be a matter of looking at the date manual on AIX.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 10 years
    Be my guest: the date manual on AIX