I want to convert 207 minutes to Houres and mins such as format (3 Hours 37 Mins). The User will enter 207 minutes and the output should be 3 hours and 37 mins.
Asked
Active
Viewed 775 times
0
-
5It is a good idea to search first, as this is a common task. Possible duplicate of [ColdFusion - Create Time from Number of Minutes](https://stackoverflow.com/questions/10146820/coldfusion-create-time-from-number-of-minutes) – SOS Sep 24 '19 at 15:11
2 Answers
2
Yikes at these answers.
Quick, elegant, smells like lavender:
<!--- This number is arbitrary, set it to whatever you want. --->
<cfset Minutes = 125>
<cfset HoursOutput = Minutes \ 60>
<cfset MinutesOutput = Minutes Mod 60>
<cfoutput>#HoursOutput# Hours and #MinutesOutput# Minutes</cfoutput>
Using a backslash instead of dividing normally eliminates the remainder in HoursOutput
(which would be formatted by default as a long decimal number) for readability.

TRose
- 1,718
- 1
- 16
- 32
-
1
-
1@JamesAMohler I only see one duplicate, and my answer is constructed differently enough that I felt it may have contributed something to the asker's understanding. There is something to be said for a simple line by line breakdown. Set this, output that. Whenever I find something on SO that I can copy and paste for a functional example of how an idea works, I feel a lot better about working with it. To each his own. – TRose Sep 25 '19 at 20:34
-2
Here is the solution
<cfset TotalMinutes = 307>
<cfset yourrequired_format= "#TotalMinutes \60# Hr #numberformat(TotalMinutes % 60, "00")# Min" />

Techleadz Team
- 198
- 2
- 15
-
-
Your output is wrong. It's return **5 Hr 07 Min **. Can you manually calculate by yourself 307 / 60 = 5.111 then how will your get 3 hr as per you code ? So you are wrong. – Kannan.P Sep 24 '19 at 13:28
-