The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using 'date' to get previous days' dates slant-40 UNIX for Dummies Questions & Answers 2 06-17-2008 08:49 PM
Script based on input mail eagercyber Shell Programming and Scripting 1 05-13-2008 02:39 AM
Checking for future / non existent dates DKNUCKLES Shell Programming and Scripting 2 10-09-2007 06:20 AM
grep a log file to filter previous dates pinpe Shell Programming and Scripting 5 08-03-2007 01:25 PM
Dates of previous years terms5 UNIX for Dummies Questions & Answers 2 03-26-2006 09:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-07-2008
Sharmila_P Sharmila_P is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 19
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 (permalink)  
Old 08-07-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
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 (permalink)  
Old 08-07-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
the date comando can do this, if im not mistaken
  #4 (permalink)  
Old 08-08-2008
Sharmila_P Sharmila_P is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 19
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 (permalink)  
Old 08-08-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
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 (permalink)  
Old 08-08-2008
Sharmila_P Sharmila_P is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 19
Please tell how i can resolve this issue?or is there any other way to get the result?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0