The UNIX and Linux Forums  


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
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 12-01-2008 11:37 PM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 08:42 PM
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 07:15 AM
a simple way of converting a date in seconds to normal date travian HP-UX 2 11-23-2006 12:25 PM

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 01-28-2008
innocent innocent is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 10
Date help

Hi,

Pls can some one help.
Need a script which will read a command line $1 which is a date,

then based on the date in $1 calc next day or previous day etc and output the result in YYYYMMDD format.

e.g abc.sh 01/01/2008

output required is
01/01/2008 + 1day = 01/02/2008
or
01/01/2008 + 3days = 01/04/2008

is it possible using
mydate=date -d "$1" +%m%d%y
j="$mydate" -d "next day" +%m%d%y (this does not work)

Thks in adv..
  #2 (permalink)  
Old 01-28-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,787
Okay. IF you will look in the Unix Forums FAQ, you will see that Perderabo wrote a script: datecalc. It is in the Date Arithmetic thread.

Cut and paste the part that does what you want.
  #3 (permalink)  
Old 01-29-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 608
Try this:


Code:
 date +%Y%m%d -d "yesterday"
 date +%Y%m%d -d "next day"
#-----4 days ago for ex.
date +%Y%m%d -d "4 day ago"
#-----4 days after 
date +%Y%m%d -d "4 day "

  #4 (permalink)  
Old 01-29-2008
pt14 pt14 is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 28
If you have perl, you could try this:

yday=`perl -e 'print scalar localtime($_) ,"\n" for time + 86400'`
  #5 (permalink)  
Old 01-29-2008
innocent innocent is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 10
Date Help

Thanks for all ur inputs.

Looks like i have not state my requirement clearly.
I am aware of
date --date='next day' "+%Y%m%d" .
This will give next date of the unix system date as an output in YYYY/mm/dd format.

But what i am looking is to get the next day or next month for any date which the user is passing as a parameter.

something like this below

mydate=$1
date --date $mydate +%m%d%Y -d ýesterday (this does not work)

but i want next day or 3rd day of mydate

Is it possible ? if so pls give me the soln.

Thks
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 03:15 PM.


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