Adding one day to a date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding one day to a date
# 1  
Old 08-19-2015
Adding one day to a date

Hi All,

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

Code:
#!/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"

Please help me.

Thanks.
# 2  
Old 08-19-2015
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)?
# 3  
Old 08-19-2015
Hi,

From GUI we are passing value (last day of the month)to $t_date.
The ksh version is Version M-11/16/88i.

From GUI we are always passing last day of the month in the format %Y%m%d.

Then I have to get the first day of the next month.

Please help me.

Thanks.

Last edited by ROCK_PLSQL; 08-19-2015 at 08:23 AM..
# 4  
Old 08-19-2015
Where do you pass the last day of the month to? To a process running an shell? Is the variable exported?
What be the version of your date command?
# 5  
Old 08-19-2015
Hi,

THis $t_date is passing from $universe tool.

Thanks.
# 6  
Old 08-19-2015
That does not answer the questions.
# 7  
Old 08-19-2015
Hi,

How to find the version of the date.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. Shell Programming and Scripting

Getting a Date value based on day

Hi, I have a scenario like this. I get a file on anyday of the week, so the file name is like this. FILE_NAME_YYYYMMDD I want to get the tuesday date before this day. For example FILE_NAME_20180413 I should get the date as 20180410 FILE_NAME_20180404 I should get the date as 20180403... (5 Replies)
Discussion started by: dnat
5 Replies

3. AIX

Need to get the next day's date of the user entered date

I need to get the next day's date of the user entered date for example: Enter date (yyyy/mm/yy): 2013/10/08I need to get the next day's date of the user entered date Desired Output: 2013/10/09Though there are ways to achieve this is Linux or Unix environment (date command) ,I need to... (1 Reply)
Discussion started by: rpm120
1 Replies

4. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

5. Shell Programming and Scripting

Adding days to system date then compare to a date

Hi! I am trying to read a file and every line has a specific date as one of its fields. I want to take that date and compare it to the date today plus 6 days. while read line do date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD if ; then ...proceed commands ... (1 Reply)
Discussion started by: kokoro
1 Replies

6. Shell Programming and Scripting

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.. (4 Replies)
Discussion started by: apple2685
4 Replies

7. UNIX for Dummies Questions & Answers

Getting date -1 day not using GNU date

It's easy as pie to get the date minus one day on opensolaris: date -d "-1 day" +"%Y%m%d"run this command on our crappy Solaris 10 machines however (which I'm guessing doesn't have GNU date running on it) and you get: date: illegal option -- d date: illegal option -- 1 date: illegal option --... (5 Replies)
Discussion started by: rich@ardz
5 Replies

8. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. UNIX for Dummies Questions & Answers

date - 1 day

Hi, I have been trying just about every unix command to come up with yesterday's date (today's date - 1). I have seen all of the help on this forum, and none of it seems to work for me here. We are using Sun Solaris 9 Unix. I am using this script to create a .txt file with ftp commands that I will... (2 Replies)
Discussion started by: sfedak
2 Replies

10. Shell Programming and Scripting

Getting day from a date...

Hi, I have a date input in MMDDYYYY format.. I have to give the day (whether that DD is sunday/monday...) Is there any command for it... Or do I have to write a script for that... Thanks in Advance Yeheya (1 Reply)
Discussion started by: yeheyaansari
1 Replies
Login or Register to Ask a Question