![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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?
|
|
#4
|
||||
|
||||
|
Quote:
typeset -Z2 prevhour=$(((${CURRTIME%???}+23)%24)) PREVTIME=${prevhour}${CURRTIME#??} |
|
#5
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |