The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help, I need to get the last date of previous month sirrtuan Shell Programming and Scripting 11 10-14-2008 06:59 AM
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 06:58 PM
Previous day's date in Perl? rajus19 Shell Programming and Scripting 4 07-18-2006 01:40 AM
Get the Previous date Nayanajith Shell Programming and Scripting 2 06-29-2006 02:39 AM
How to find Previous date and Coming date arunava_maity UNIX for Dummies Questions & Answers 2 05-24-2001 12:41 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 04-17-2008
developncode developncode is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 14
Question KSH Checking Previous Date**

How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous date which is April 16th 2008 stored in the following format (20080416) <- (YYYYMMDD). I breifly thought that I could just subtract 1 from the day (DD) amount, but the only problem is what if it is the 1st of the month, I would then be unable to tell if it should be the 30th, 31st, or even the 29th? Please help. Thanks all
  #2 (permalink)  
Old 04-17-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
One way:

Code:
#!/bin/ksh

perl -e ' use POSIX qw(strftime); print strftime "%Y%m%d\n", localtime(time - 86400);  ' | read yest
echo $yest

  #3 (permalink)  
Old 04-17-2008
developncode developncode is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 14
Thanks for the quick reply, Do you know any other way that I could do it?...I was trying to find a way to do it without using perl?
  #4 (permalink)  
Old 04-17-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
If you have gnu date or install the gnu version of date it will do that.

If you care to install ksh93 instead of ksh88 it will do that.

The only other option is to write a fairly large piece of shell code.
Go to the FAQ - look for Perderabo's 'Date Arithmetic' thread. There are examples there.
  #5 (permalink)  
Old 04-17-2008
denn denn is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 96

Code:
#!/usr/bin/ksh
YESTURDAY=`TZ=EST+24 date +%Y%m%d`
echo $YESTURDAY

Note: if your timezone is something other than EST5DST just put in what your's is and it should work just fine. Some OS's you can change more than 1 day, HP-UX one day is as far as you can go with this approach.
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 07:35 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