Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Totaling Time

by lhoward (Vicar)
on Jul 25, 2001 at 22:11 UTC ( #99754=note: print w/replies, xml ) Need Help??


in reply to Totaling Time

You'd probably be better off if you had stored your times using your database's native date/time format (instead of munging with integer col's). But in short:
my $tdiff = ($hour1 - $hour2) * 60 + ($min1 - $min2); my $diff_hour = int(tdiff / 60); my $diff_min = $tdiff % 60;

Replies are listed 'Best First'.
Re: Re: Totaling Time
by lestrrat (Deacon) on Jul 25, 2001 at 22:28 UTC

    I have some comments to add: specifically, about using the database date/time format/type.

    If you are going to do any sort of transformation/computation of date/time within perl, I recommend storing the data as an integer ( seconds since epoch time ) in order to reduce overhead.

    You may argue that you can do this transformation in the SQL statements, but it's still a huge performance hit ( as far as I could tell ) when you are dealing with tens and hudreds of thousands of record which each needs to have the epoch time format in order to do some calculations

    In my case, I needed to fit a certain API that expected epoch time to do its processing. I tried it with a) store date/time in db format, covert upon fetch b) sotre data/time in db format, convert from within SELECT statement c) store data/time as seconds since epoch time, no conversion

    This yielded in roughly a) and b) taking the same amount of time, where as c) took about half of the time that it took for a) and b).

    So, depending on your application, I strongly urge you to use epoch time instead of native date/time format

Re: Re: Totaling Time
by RhetTbull (Curate) on Jul 25, 2001 at 22:29 UTC
    Of course that assumes that the start and stop occured on the same day. If nlafferty's data crosses day boundaries (e.g. it started at 10:55PM and ended at 2:30AM) then the answer becomes much more complicated.
      Complications aside, without dates it is impossible to know if more than one day has elapsed between the start and end times.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://99754]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2019-08-24 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?