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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to subtract data of two different file krishna_sicsr Shell Programming and Scripting 2 03-28-2007 09:13 PM
script for add and subtract two hours ZINGARO Shell Programming and Scripting 7 08-17-2006 05:04 AM
Subtract two dates in different lines vanand420 UNIX for Dummies Questions & Answers 1 07-10-2005 10:40 PM
Subtract date & time in diferent rows vanand420 UNIX for Dummies Questions & Answers 1 07-10-2005 05:07 AM
Subtract two date in unix vanand Shell Programming and Scripting 1 06-18-2005 04:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-01-2005
Registered User
 

Join Date: Aug 2003
Posts: 27
Subtract Time

Hello,

Im writing a script using the ksh shell. I have 2 variables in the script:

CURRTIME
PREVTIME

Example, if CURRTIME=13:00, I want to somehow calculate what the time was an hour ago so that PREVTIME=12:00

Right now I have the following:

CURRTIME=`date +%H:%M`

How can I determine PREVTIME based on the CURRTIME?
Reply With Quote
Forum Sponsor
  #2  
Old 12-01-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
You never mentioned which OS.

Here is GNU date option.

Code:
-bash-2.05b$ date
Thu Dec  1 19:59:45 PST 2005
-bash-2.05b$ date -d "1 hour ago"
Thu Dec  1 18:59:50 PST 2005
Reply With Quote
  #3  
Old 12-03-2005
Registered User
 

Join Date: Aug 2003
Posts: 27
The OS is Digital Unix and Tru64 Unix. I wont be able to test your command until Monday. Do you know if it works on those OSes?
Reply With Quote
  #4  
Old 12-03-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Quote:
Originally Posted by xadamz23
The OS is Digital Unix and Tru64 Unix. I wont be able to test your command until Monday. Do you know if it works on those OSes?
I doubt it. But with ksh:
typeset -Z2 prevhour=$(((${CURRTIME%???}+23)%24))
PREVTIME=${prevhour}${CURRTIME#??}
Reply With Quote
  #5  
Old 12-03-2005
Registered User
 

Join Date: Aug 2003
Posts: 27
Quote:
Originally Posted by Perderabo
I doubt it. But with ksh:
typeset -Z2 prevhour=$(((${CURRTIME%???}+23)%24))
PREVTIME=${prevhour}${CURRTIME#??}
Thank you very much Perderabo, but I realized something after I posted my question. I need the format of the date to be '02-dec-2005:15:30'. I need to have the date included so my script will work after midnight on the next day. Do you have any idea how to accomplish that?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0