I want to add one day to a date and store it in a variable.
From GUI we are passing value (last day of the month)to $t_date.
This $t_date will give me the value like this %Y%m%d 20150531.
Now I want to add one day to this value and store it in a variable "datein".
datein should give me the first day of the next month i.e. 20150601.
I tried the below script it 's not working
#!/bin/ksh
echo "Initialization"
echo "str Date : $t_date"
echo "str Date = First day of the month"
datein=`$t_date '+%Y%m%d'`
datein=$((datein +1))
echo "$datein"
The value of t_date in your script will not magically become the last day in some previous month unless something explicitly sets it to that value. Nothing in the script you have shown us sets the variable t_date to any value.
The ways you can calculate relative dates vary considerably from system to system and shell to shell.
What operating system are you using?
Do you have access to a 1993 or later version of the Korn shell ( ksh93 or a ksh with a version later than 1993)?
And, if the OP doesn't have a Linux system, but does have a 1993 or later ksh , the following works correctly when $t_date expands to a YYYYMMDD representation of the last day of any month:
printf '%(%Y%m%d)T\n' "$t_date + 1 day"
And, we could all write code that will work in any POSIX conforming shell on any system if the submitter would only tell us what OS an shell is being used. But, I'm not going to waste my time doing that again until the submitter answers the simple questions I asked in post #2 in this thread:
so we can provide the help the submitter needs with a solution that will work in the submitter's environment.