To get previous or future dates based on input value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To get previous or future dates based on input value
# 1  
Old 08-07-2008
To get previous or future dates based on input value

Hi,
I need something like,
if the input date is 24/Aug/2008 and the inputvalue is +8 then the result should be 1/Sep/2008 (8 days after the input date)
if the input date is 24/Aug/2008 and the inputvalue is -8 then the result should be 16/Aug/2008 (8 days before the input date)

is there any command in unix,using which i can get this.Please guide me.

Thanks.
# 2  
Old 08-07-2008
If you have the latest version of ksh93
Code:
$ printf "%(%e/%b/%Y)T\n"  "24/Aug/2008 8 days ago"
16/Aug/2008
$ printf "%(%e/%b/%Y)T\n"  "24/Aug/2008 8 days"
 1/Sep/2008
$

# 3  
Old 08-07-2008
the date comando can do this, if im not mistaken
# 4  
Old 08-08-2008
Hi,

Its not helping as I don't have this version.
I tried something like this.
Code:
let noofdays=$1
let totaldays=24*noofdays
DATE_STAMP=`TZ=CST-$totaldays date +%d/%b/%Y `
echo "$DATE_STAMP"
Its working fine.but when I tried to replace the current date with the given input date I am getting some error.
Code:
let noofdays=$1
let inputdate=$2
let totaldays=24*noofdays
DATE_STAMP=`TZ=CST-$totaldays $inputdate `
echo "$DATE_STAMP"
input:
------
$1=2
$2=24/Jan/2008
error:
------
24/Jan/2008: No such file or directory
Why I am getting this error.how I can resolve this?any suggestion please..
# 5  
Old 08-08-2008
Because 24/Jan/2008 is the syntax for a file called 2008 which lives in a subdirectory called Jan which lives in a subdirectory called 24.
# 6  
Old 08-08-2008
Please tell how i can resolve this issue?or is there any other way to get the result?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find previous string based on an input string?

Hi, I did some research but cannot find the right solution so hopefully someone can help me here. I have a long string format like: VAR=111:aaaa,222:bbb,333:ccc it could be VAR=111:aaa,222:bbb,333:ccc,444:ddd, etc what I looking for is eg. if I give ccc, it will return me 333... (2 Replies)
Discussion started by: netbanker
2 Replies

2. Shell Programming and Scripting

Need simple script to generate future dates

Hi All, I am looking into a script which will give me a future dates for 7 days, including next month dates in case if runs on month ends... I an able to get this in Linux but not working for Solaris. OS: Solaris 10 Please help (6 Replies)
Discussion started by: nanz143
6 Replies

3. Shell Programming and Scripting

Getting the previous month as input for the script

Hi Experts , I have scheduled a script "createstructure "in crontab. The script runs every month on 25th . I am trying to pass the input to the script as the <year><previousmonth>.For example ,if it is running in the month of March 2014 ,the input should be "201402" (2014-year 02-previous... (7 Replies)
Discussion started by: Pradeep_1990
7 Replies

4. Shell Programming and Scripting

Display previous days dates in ksh

---------- Post updated at 03:42 AM ---------- Previous update was at 03:38 AM ---------- Sorry for a duplicate post, my post at the first place could not appear due to some net issue on my machine. Here is what i posted earlier: Hi, i am using ksh in Solaris, i wanted to assign today's,... (5 Replies)
Discussion started by: pr5439
5 Replies

5. Linux

Get all the files from a FTP location with previous week's dates in the file names using Linux

I have a weird requirement where I have to get the files from a FTP(Lets say FTP1) location and place it on my current FTP(Lets say FTP2) location. The issue is, these are daily files (in a pattern Sales_YYYYMMDD_report.csv) and are placed every day on FTP1 and my process usually runs on Monday(eg.... (2 Replies)
Discussion started by: dhruuv369
2 Replies

6. Shell Programming and Scripting

Future dates.

If I have a script that writes the name of the file based on today, tomorrow, and the day after tomorrow. How would I modify the line echo "filename.${PDY}${CYC}" >>CONTROL to reflect tomorrow and the day after tomorrow and write it to the file called CONTROL? Since ${PDY} shows... (2 Replies)
Discussion started by: libertyforall
2 Replies

7. UNIX for Dummies Questions & Answers

using 'date' to get previous days' dates

I am familiar with using the 'date' command to get the current date but I have a situation where I need to get the previous day's date as well as the date two days prior. Theoretically I could use 'expr' to compute these values but I need it to work in instances where the previous month's dates... (2 Replies)
Discussion started by: slant-40
2 Replies

8. Shell Programming and Scripting

Checking for future / non existent dates

'm attempting to script an application for the bash shell. The application needs to check for birthday, but must check the birthday to see if the date is a) in the future b) exists at all (ie Feb 29th during non-leap years). The input is being entered in a YYYYMMDD format, so I was hoping someone... (2 Replies)
Discussion started by: DKNUCKLES
2 Replies

9. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies

10. UNIX for Dummies Questions & Answers

Dates of previous years

Is there any way to use date with previous dates such as "2 23 2000" in order to see what day of the week it was? I tried changing the current date to "date 022300452000" but then it told me that I could not do this because I was "Not the owner". Any other ways of getting the day result? (2 Replies)
Discussion started by: terms5
2 Replies
Login or Register to Ask a Question