Solved

# Converting number into Hours and minutes

Posted on 2005-04-14
970 Views
Last Modified: 2012-05-05
Newbie here with simple question In Business Objects.

Field 1 = Start Time ( which is a dimension)
Field 2 = Stop Time ( dimension again)
Field 3 = Elapsed Time ( measure)

Example:

Room Time Start          Room Time Stop          Elapsed Time
10:07                          11:53                          106

I want to create a variable that will show the 106 as 1:46 ( one hour and forty six minutes)

Of course after dividing by 60 I get 1.77 and tried to reformat as HH:mm with no luck

Any advise would be greatly appreciated...

0
Question by:m3gd05
3 Comments

Accepted Solution

divide 106 with 60 and then truncate decimal places from it. so you would get
1 and 0.77 in different variables. then you can multiply 0.77 with 60 to get minutes (46.2)
you now can do the same here to get seconds (0.2 * 60 = 12). if you don't need seconds, just
don't extract the, use the integer value of 46.2 (46) for minutes.
0

LVL 7

Expert Comment

If your storage of the start and stop times are a single number, and you are subtracting them to get the elapsed time, I would think you could simply pass the elapsed time to the formatter and get the correct result.

Otherwise, try something like:

Assuming E is elapsed time, EH is elapsed hours, EM is elapsed minutes.

Divide E by 60, keep only integer part of result (no decimals)
Store in EH
Subtract  EH*60 from E
Store in EM
Output string of EH, colon, EM
0

Expert Comment

C++ Builder:
String time_reformat(int time_value)
{
double hours = time_value / 60;
double minutes = (time_value / 60 - Integer(hours))*60;
String result = String(Trunc(hours)) + String(":") + String(Trunc(minutes));
return result;
}

MS .NET C++:
C++ Builder:
CString time_reformat(int time_value)
{
double hours = time_value / 60;
double minutes = (time_value / 60 - TRUNC(hours, 0))*60;
CString result = CString(TRUNC(hours, 0)) + CString(":") + CString(TRUNC(minutes, 0));
return result;
}

I hope it is right, i never tested it.
0

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

### Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

#### 759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!