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
Related videos on Youtube
Author by
cm60
Updated on September 18, 2022Comments
-
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 over 10 yearsNo input validation is performed here, so if the user enters an invalid date format, perl will complain.
-
Angel Todorov over 10 yearsDid you check? I believe that Time::Piece and Time::Seconds are core Perl modules.
-
cm60 over 10 yearsYes. 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 over 10 years:Can you please help me to edit the above piece of code.
-
Gilles 'SO- stop being evil' over 10 yearsNot on AIX you can't. This would work on Linux.
-
Gilles 'SO- stop being evil' over 10 yearsNot on AIX you can't. This would work on Linux.
-
Marek Zakrzewski over 10 yearsOh I totally missed AIX.It would be a matter of looking at the
date
manual on AIX. -
Gilles 'SO- stop being evil' over 10 yearsBe my guest: the date manual on AIX