SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 20th, 2008, 06:17 AM
ali560045 ali560045 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 13 ali560045 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 8 m 48 sec
Reputation Power: 0
Time difference in a file

i have a script that gives me the start time and end time.

how to calculate the time difference b/w the two

here is the o/p of a file

Start Time:
2008-02-19 00:13:16,338

End Time:
2008-02-19 23:43:17,974
-------------------------------------------------

how to find the difference b/w the two time ?

Reply With Quote
  #2  
Old March 8th, 2008, 06:32 AM
Isuwyn Isuwyn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Belgium
Posts: 3 Isuwyn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 34 sec
Reputation Power: 0
Quote:
Originally Posted by ali560045
i have a script that gives me the start time and end time.

how to calculate the time difference b/w the two

here is the o/p of a file

Start Time:
2008-02-19 00:13:16,338

End Time:
2008-02-19 23:43:17,974
-------------------------------------------------

how to find the difference b/w the two time ?


I think it is almost impossible to do it with those timestamps...
If the time provided would be in milliseconds (since 1970) you could use the following script:

tail +5 yourfile.txt | head -n 1 > endtime
tail +2 yourfile.txt | head -n 1 > starttime
paste -d"-" endtime starttime > difftime
echo quit >> difftime
cat << Here
Time difference: `bc difftime`
Here
rm endtime
rm starttime
rm difftime

In "tail +5" and "tail +2" you can replace the number by the line on which the number of milliseconds can be found.
And yourfile.txt is the file in which the Start time and End time is stored.


Hope this helps,

Isuwyn

Reply With Quote
  #3  
Old March 8th, 2008, 11:05 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 591 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 59 m 46 sec
Reputation Power: 100
Send a message via AIM to L7Sqr
If you pass that date/time string to an outside script, you can convert it to another format. I dont know of a way to do it natively in the shell, but Ruby and Python come to mind as an easy alternative.
__________________
-- I'll provide you with reference points; if they dont work, refer to something else.

If you process text, this might make your life a little easier.

Reply With Quote
  #4  
Old March 20th, 2008, 06:48 AM
pdreyer pdreyer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 38 pdreyer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 1 m 37 sec
Reputation Power: 1
Quote:
Originally Posted by ali560045
i have a script that gives me the start time and end time. How to calculate the time difference b/w the two

Start Time:
2008-02-19 00:13:16,338

End Time:
2008-02-19 23:43:17,974


With ksh script:
datediffms 2008 02 19 00 13 16 338 2008 02 19 23 43 17 974
23:30:01,636

And the code for datediffms
Code:
#!/usr/bin/ksh
dt2ms() { # ccyy mm dd HH MM SS nnn to miliseconds
y=$1 m=${2}-1 d=$3 H=$4 M=$5 S=$6 f=$7 a=$((12*$y+$m-2)) b=$(($a/12)) 
printf "$(((86400*((367*$a+7)/12-2*$b+$b/4+$d-$b/100+$b/400-719469)\
+$H*3600+$M*60+$S)*1000+$f))" 
}
hmsf() { # miliseconds to hh:mm:ss.nnn
s=$(($1/1000)) H=$(($s/3600)) M=$((($s-$H*3600)/60)) S=$(($s-$H*3600-$M*60))
printf "%02s:%02s:%02s,%03s\n" $H $M $S $(($1-$1/1000*1000))
}
printf "$(hmsf $(($(dt2ms $8 $9 ${10} ${11} ${12} ${13} ${14}) \
- $(dt2ms $1 $2 $3 $4 $5 $6 $7))))\n"

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Time difference in a file


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway