0

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.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Basit Ali
  • 155
  • 6
  • 5
    It 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 Answers2

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
    How is this better than the possible duplicates? – James A Mohler Sep 24 '19 at 22:50
  • 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