Re: Time Calculation

new topic     » goto parent     » topic index » view thread      » older message » newer message

Thanks for everyone's help! here's what i managed to come up with if
anyone's interested. It works for any time values.

--t1 and t2 are: {hours, minutes, seconds, 0/1 (Am/Pm)}
--returns the number of hours between t1 and t2

function time_difference(sequence t1, sequence t2)
integer shour, smin, ssec, sampm
integer ehour, emin, esec, eampm
atom totals, totale

-- give those var's some values.
    shour = t1[1]
    smin = t1[2]
    ssec = t1[3]
    sampm = t1[4]

    ehour = t2[1]
    emin = t2[2]
    esec = t2[3]
    eampm = t2[4]

    --swap am/pm with 12 hours so it'll add up right.
    if ehour = 12 then
 eampm = (not eampm)
    end if
    if shour = 12 then
 sampm = (not sampm)
    end if

    -- Get rid of the AMPM thing
    if eampm != sampm then
 ehour = ehour + 12
    end if

    --convert to seconds and add them all up
    totals = ((shour * 60) + smin)*60 + ssec
    totale = ((ehour * 60) + emin)*60 + esec

    --convert to hours
    totals = totals / 60 / 60
    totale = totale / 60 / 60

    if totale = totals then -- start and finish at the same time
 return 24
    elsif totals < totale then --start time and end time on same day.
 totale = totale-totals
 return totale
    else --start time and end times are on different days
 totale = (24-totals) + totale
 return totale
    end if
end function

--Mark
  --Liquid-Nitrogen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu