If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell : Fow to find Time Difference

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-04, 04:26
preetikate preetikate is offline
Registered User
 
Join Date: Jan 2004
Posts: 84
Shell : Fow to find Time Difference

> echo $ANA_ST
06-feb-2004 11:21:11

s> echo $ANA_ED
06-feb-2004 11:23:17

how can difference be taken of dates and times to find the time taken?
Reply With Quote
  #2 (permalink)  
Old 02-06-04, 06:23
preetikate preetikate is offline
Registered User
 
Join Date: Jan 2004
Posts: 84
Any Suggestions?
Reply With Quote
  #3 (permalink)  
Old 02-07-04, 03:14
preetikate preetikate is offline
Registered User
 
Join Date: Jan 2004
Posts: 84
Need help!!
Reply With Quote
  #4 (permalink)  
Old 02-07-04, 12:15
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
If your shell is ksh, your problem is resolved.
  • Download the following script : [url]days
  • In your script, add the following code :
    Code:
    . days
    
    function difftimes {
       typeset dt1=$1
       typeset dt2=$2
       set $(echo $dt1 | tr ':-' '  ')
       unixtime $3 $2 $1 $4 $5 $6
       integer t1=unixtime
       set $(echo $dt2 | tr ':-' '  ')
       unixtime $3 $2 $1 $4 $5 $6
       integer t2=unixtime
       echo $((t2-t1))
    }
  • The 'difftimes' function write to stdout the difference (seconds) between two dates:
    Code:
    ANA_ST="06-feb-2004 11:21:11" 
    ANA_ED="06-feb-2004 11:23:17"
    ANA_TI=$(difftimes "$ANA_ST" "$ANA_ED")  # result 126 (seconds)
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 02-07-04, 12:23
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
the script 'days' is at The armory.com Anonymous FTP Archives
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On