Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    84

    Unanswered: 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?

  2. #2
    Join Date
    Jan 2004
    Posts
    84
    Any Suggestions?

  3. #3
    Join Date
    Jan 2004
    Posts
    84
    Need help!!

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

  5. #5
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    the script 'days' is at The armory.com Anonymous FTP Archives
    Jean-Pierre.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •