Skip to main content
Participant
June 23, 2009
Answered

Time difference in decimal

  • June 23, 2009
  • 1 reply
  • 815 views

Hello All,

I have an application that allows employees to enter a vacation request.  If they are taking a partial day, they enter the start time and end time and it is stored in the database as military time (for example: start - 13:00; end - 17:00).   I then display the list of vacations on a dashboard application for managers to view.

Occasionally, an employee will enter a time such as 13:30 - 17:00.  I want to display this on the screen as 3.5 hours.

My current application used DateDiff to calculate the time difference:

     <cfset vacation_hours_taken = (DateDiff("h",qryVacationPDO.time_started, qryVacationPDO.time_ended))>

One, is there a better way to determine the hours difference between the two times, and

Two, is there a way to convert the 3 hours and 30 minutes (3:30) to decimal format (3.5)?

Thanks for any help you can provide.

Regards,

Robert

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    For simple a decimal value, Grab the number of minutes instead.  Then divide it by 60. You can use NumberFormat to tweak the number output.

             dateDiff("n", time_started, time_ended)

    For fancier options, you may want to check the DateTime Library at www.cflib.org. Chances are they have a function for whatever you need to do.

    HTH

    Leigh

    1 reply

    -__cfSearching__-Correct answer
    Inspiring
    June 23, 2009

    For simple a decimal value, Grab the number of minutes instead.  Then divide it by 60. You can use NumberFormat to tweak the number output.

             dateDiff("n", time_started, time_ended)

    For fancier options, you may want to check the DateTime Library at www.cflib.org. Chances are they have a function for whatever you need to do.

    HTH

    Leigh

    Participant
    June 23, 2009

    Thanks Leigh!   That worked perfectly.   So easy I couldn't see it.  :-(

    I looked at cflib.org, but didn't find anything.  Maybe I didn't look hard enough.

    Regards,

    Robert

    Inspiring
    June 23, 2009

    They have all kinds of functions separated into different libraries: dateTime, string functions, etcetera.  It just depends on what you want to do ;-)  For example, the HourRound function from the Date Library converts a decimal time into the nearest quarter of an hour.  I am not saying you need a function here. It sounds like basic math will work.  But cflib.org is usually the first place I check when I need something outside the basic CF functions.

    http://www.cflib.org/udf/hourRound

    http://www.cflib.org/library/DateLib

    - Leigh