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
date manipulation pstanand Shell Programming and Scripting 6 04-03-2008 10:11 AM
Manipulation of Date in Shell jnanesh.b Shell Programming and Scripting 1 01-11-2008 01:16 PM
Date Manipulation mgirinath Shell Programming and Scripting 6 04-03-2007 04:25 AM
Help with log manipulation StevePace Shell Programming and Scripting 3 01-31-2006 08:28 PM
Time/date manipulation choice High Level Programming 1 02-01-2002 04:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-10-2004
jalburger jalburger is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 69
date manipulation

I'm writing a ksh script in which I want to present the user with a choice of choosing any of the last 15 days. i.e., a list like the following:

20040510 (today)
20040509 (yesterday)
20040508
.
.
.
20040426

Is there an easy way to produce the date from x number of days ago other than converting today's date into Julian (day of the year) and then converting that into a month and day?

Thanks in advance!
  #2 (permalink)  
Old 05-10-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Go to our home page.

Click on "Answers to Frequently Asked Questions".

Click on "Yesterdays Date/Date Arithmetic".
  #3 (permalink)  
Old 05-10-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
I wouldn't use the shell for date arithmetic, if you have perl installed...
Code:
#!/usr/bin/ksh
Days=15
PS3='Choose a date (or q to quit) ? : '
select Date in $(perl -e '
  $d = time();
  for ($i = 0; $i < $ARGV[0]; $i++) {
    @f = localtime($d);
    printf "%04d%02d%02d\n", $f[5]+1900, $f[4]+1, $f[3];
    $d-=86400;
  }' $Days)
do
  break
done
echo Date is ${Date?Aborted}
  #4 (permalink)  
Old 05-10-2004
jalburger jalburger is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 69
Thanks Perderabo & Ygor!!....it definitely looks easier to do with Perl instead of the shell. I don't use Perl very often...I didn't realize it had easy to use date functions. You have just saved me a few hours of headache.
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 10:04 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