Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- ColdFusion
- >
- Date and time diff?

Highlighted
## How to Convert Minutes to Hours and Minutes, Alternate Method

Explorer
,

Dec 27, 2018

Copy link to clipboard

Copied

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

LEGEND

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

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.

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Explorer
,

Dec 27, 2018

Copy link to clipboard

Copied

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

LEGEND

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

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.

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

bloodbanker

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/td-p/10257020
13
Replies
13

LEGEND
,

Dec 27, 2018

Copy link to clipboard

Copied

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.

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Reply

Loading...

WolfShade

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257021#M180867
Explorer
,

Dec 27, 2018

Copy link to clipboard

Copied

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**)

Community Guidelines

Reply

Loading...

bloodbanker

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257022#M180868
LEGEND
,

Dec 27, 2018

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

WolfShade

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257024#M180870
LEGEND
,

Dec 27, 2018

Copy link to clipboard

Copied

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

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.

Community Guidelines

Reply

Loading...

WolfShade

Dec 27, 2018
1
/t5/coldfusion/date-and-time-diff/m-p/10257023#M180869
Explorer
,

Dec 27, 2018

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

bloodbanker

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257025#M180871
LEGEND
,

Dec 27, 2018

Copy link to clipboard

Copied

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

V/r,

^ _ ^

Community Guidelines

Reply

Loading...

WolfShade

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257026#M180872
LEGEND
,

Dec 27, 2018

Copy link to clipboard

Copied

OOOOOOH! I just learned something way cool.

You can do it using a modulus!!

Using the example above of 190 minutes:

190 / 60 = 3.16667 (3 is the hours, use floor() to round that down to just 3)

190 % 60 = 10 (the number of minutes without calculating or rounding down)

How cool is THAT????

V/r,

^ _ ^

Community Guidelines

Reply

Loading...

WolfShade

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257027#M180873
Adobe Community Professional
,

Dec 27, 2018

Copy link to clipboard

Copied

<cfset cc_TIC_cooler_good_untilDiff_in_minutes = dateDiff("n", now(), cc_TIC_cooler_good_until)>

<cfset numberOfHours=int(cc_TIC_cooler_good_untilDiff_in_minutes/60)>

<cfset numberOfMinutes=cc_TIC_cooler_good_untilDiff_in_minutes - 60*int(cc_TIC_cooler_good_untilDiff_in_minutes/60)>

Community Guidelines

Reply

Loading...

BKBK

Dec 27, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257028#M180874
LEGEND
,

Dec 28, 2018

Copy link to clipboard

Copied

I just learned something EVEN MORE COOL!!!

According to Ben Nadel, ever since CF7 there has been a math function "\" that is "integer division". It does the same thing as using int() on the results (ie, it will automatically remove the decimal and everything after it.) So it is now even easier:

190 \ 60 = 3

190 % 60 = 10 (the number of minutes without calculating or rounding down - it's the REMAINDER.)

Mind. Blown.

V/r,

^ _ ^

Community Guidelines

Reply

Loading...

WolfShade

Dec 28, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257029#M180875
Adobe Community Professional
,

Dec 28, 2018

Copy link to clipboard

Copied

Community Guidelines

Reply

Loading...

BKBK

Dec 28, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257030#M180876
LEGEND
,

Dec 28, 2018

Copy link to clipboard

Copied

They may not be faster, and may not be intuitive (although I'll argue mod v % as % being intuitive.. it just makes sense, to me; JavaScript has used % to represent modulus for quite a while), it's less code to write. That is typically enough, for me (although not always.)

V/r,

^ _ ^

Community Guidelines

Reply

Loading...

WolfShade

Dec 28, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257031#M180877
Adobe Community Professional
,

Dec 29, 2018

Copy link to clipboard

Copied

WolfShade wrote

... it's less code to write.

Fair enough.

Community Guidelines

Reply

Loading...

BKBK

Dec 29, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257032#M180878
WolfShade
LATEST

LEGEND
,

Dec 31, 2018

Copy link to clipboard

Copied

I know I'm kind of splitting hairs, here, but I just realised that I shouldn't have called it "modulus". I should have called it "remainder". Apparently, for positive values they are identical. But negative values are different between mod and rem.

https://stackoverflow.com/questions/13683563/whats-the-difference-between-mod-and-remainder

V/r,

^ _ ^

Community Guidelines

Reply

Loading...

WolfShade

Dec 31, 2018
0
/t5/coldfusion/date-and-time-diff/m-p/10257033#M180879
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.