Skip to main content
Known Participant
December 27, 2018
Answered

Date and time diff?

  • December 27, 2018
  • 2 replies
  • 1345 views

I am showing a datediff using just hours.  Can I show hours and minutes?  I am using CF10, and I am not a programmer.

Here is what I am using

<cfset cc_TIC_cooler_good_untilDiff = DateDiff("h", Now(), cc_TIC_cooler_good_until)>    cc_TIC_cooler_good_until = date/time stored in database.

Thank you

    This topic has been closed for replies.
    Correct answer WolfShade

    According to calculatorsoup.com, a method (dubbed the alternative method) to calculate hours:minutes from minutes is to:

    How to Convert Minutes to Hours and Minutes, Alternate Method

    There are 60 minutes in an hour or 60 minutes per hour. Written mathematically as a value of 1 it is [60 min / 1 hr] = 1. The inverse is also true that [1 hr / 60 min] = 1

    To convert minutes to hours and minutes by division and multiplication,

    • divide the minutes by 60
    • if the result is a number with a decimal part, then
    • the hours is the integer part
    • the minutes is the decimal part multiplied by 60

    To show an example and how it works mathematically, let's say we want to convert 190 minutes to hours and minutes. We multiply by [1 hr / 60 min] which is 1. The min unit cancels out and our result is in hr units.

    190 min * [1 hr / 60 min] = 190/60 hr = 3.16667 hr

    3 is the hours part.

    The minutes part is calculated as 0.16667 * 60 = 10

    So, 190 minutes = 3 hours and 10 minutes.

    2 replies

    WolfShade
    WolfShadeCorrect answer
    Legend
    December 27, 2018

    According to calculatorsoup.com, a method (dubbed the alternative method) to calculate hours:minutes from minutes is to:

    How to Convert Minutes to Hours and Minutes, Alternate Method

    There are 60 minutes in an hour or 60 minutes per hour. Written mathematically as a value of 1 it is [60 min / 1 hr] = 1. The inverse is also true that [1 hr / 60 min] = 1

    To convert minutes to hours and minutes by division and multiplication,

    • divide the minutes by 60
    • if the result is a number with a decimal part, then
    • the hours is the integer part
    • the minutes is the decimal part multiplied by 60

    To show an example and how it works mathematically, let's say we want to convert 190 minutes to hours and minutes. We multiply by [1 hr / 60 min] which is 1. The min unit cancels out and our result is in hr units.

    190 min * [1 hr / 60 min] = 190/60 hr = 3.16667 hr

    3 is the hours part.

    The minutes part is calculated as 0.16667 * 60 = 10

    So, 190 minutes = 3 hours and 10 minutes.

    Known Participant
    December 27, 2018

    Thank you, I never thought of working with the whole thing in minutes and converting it, I'll give that a try.

    WolfShade
    Legend
    December 27, 2018

    Thank you for marking my answer as correct.  I do appreciate it.

    V/r,

    ^ _ ^

    WolfShade
    Legend
    December 27, 2018

    Yes, DateDiff("h" is for hours.  DateDiff("n" is for minutes, DateDiff("s" is for seconds.

    https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/DateDiff.html

    V/r,

    ^ _ ^

    UPDATE:  I just noticed you said "hours and minutes".  So, in that case you'd get the difference in minutes, and convert to hours:minutes using simple math.

    Known Participant
    December 27, 2018

    Thanks, I do know that much. 

    What I want to show is a good until date time, and then in parenthesis after that how many hours and minutes that is.

    What I have is:

    12/28/2018 02:44

    (11)

    What I want is:

    12/28/2018 02:44

    (11:48)

    WolfShade
    Legend
    December 27, 2018

    And then just use floor() to round down to the nearest integer because 0.16667 * 60 doesn't equal 10, it equals something like 10.0002, or something.