The UNIX and Linux Forums  


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



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

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2009
Registered User
 

Join Date: Mar 2008
Posts: 35
Obtaining day before a given date

Hi all,

is there a way using GNU (Solaris 8) methods of obtaining the day before a given day?

i.e. 2007-09-09.... I would like the date a day before it so output would be 2007-09-08. Format YYYY-MM-DD

I know I can subtract the day number using cut and expr but it would get tricky if the date was 2007-09-01 for example and would also make my script long with all the permutations of checking months, years etc.
  #2 (permalink)  
Old 11-30-2009
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,434

Code:
$ date -d '2007-09-09 1 day ago' +'%F'
2007-09-08
$

Jean-Pierre.
  #3 (permalink)  
Old 11-30-2009
Registered User
 

Join Date: Mar 2008
Posts: 35
Quote:
Originally Posted by aigles View Post
Code:
$ date -d '2007-09-09 1 day ago' +'%F'
2007-09-08
$

Jean-Pierre.
Thanks Jean-Pierre but i am afraid i cannot use the -d option.

I get the following:

date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
  #4 (permalink)  
Old 11-30-2009
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,434
-d (or --date) is an option that is specific to the GNU version of date.

Seems that you don't use GNU commands.
In that case, consult the post Yesterdays Date/Date Arithmetic

Jean-Pierre.
Sponsored Links
Reply

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
obtaining a particular day johnray31 Shell Programming and Scripting 2 07-26-2006 07:47 AM
Obtaining Process information on AIX StuBob High Level Programming 0 01-05-2005 07:13 AM
Obtaining A Process ID (PID) 1cuervo UNIX for Advanced & Expert Users 7 11-05-2001 12:36 AM
Obtaining IP address Raael IP Networking 1 05-31-2001 02:12 PM



All times are GMT -4. The time now is 10:28 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