Highlighted

How to convert minutes to decimal

Participant ,
Jun 30, 2014

Copy link to clipboard

Copied

I need to convert my minutes in my HH:MM record to decimal.

For example if I have 43 hours and 15 minutes (43:15) I need to return the result 43.25 hours

and if i have 10 hours and 30 minutes I need to return 10.50 hours.

How do I do this?

TOPICS
Getting started

Views

428

Likes

Translate

Translate

Report

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

How to convert minutes to decimal

Participant ,
Jun 30, 2014

Copy link to clipboard

Copied

I need to convert my minutes in my HH:MM record to decimal.

For example if I have 43 hours and 15 minutes (43:15) I need to return the result 43.25 hours

and if i have 10 hours and 30 minutes I need to return 10.50 hours.

How do I do this?

TOPICS
Getting started

Views

429

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 30, 2014 0
Most Valuable Participant ,
Jun 30, 2014

Copy link to clipboard

Copied

How do I do this?

The simple answer: with math.

Longer answer: parse it using list functions and then do some math.  Like this:

<cfset MyTime = "43:15">

<cfset hours = ListFirst(MyTime, ":") > <!--- get the hours part --->

<cfset minutes = ListLast(MyTime, ":") > <!--- get the minutes part --->

<cfset decimalMinutes = minutes / 60 > <!--- Calculate minutes as decimal of an hour --->

<cfset MyDecimalTime = hours + decimalMinutes > <!--- Put it all back together as decimal hours --->

Or, in more terse form:

<cfset MyTime = "43:15">

<cfset MyDecimalTime = ListFirst(MyTime, ":") + (ListLast(MyTime, ":") / 60) >

HTH,

-Carl V.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 30, 2014 0
BKBK LATEST
Adobe Community Professional ,
Jul 01, 2014

Copy link to clipboard

Copied

If you need to round off to 2 decimals and to pad with 0s, that is, 10.50 instead of 10.5, then adapt Carl's solution to

<cfset MyDecimalTime = numberFormat(ListFirst(MyTime, ":") + (ListLast(MyTime, ":") / 60), "00.00")>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 01, 2014 0