[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Converting number into Hours and minutes

Posted on 2005-04-14
Medium Priority
1,023 Views
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
• 2

Accepted Solution

beawhac earned 150 total points
ID: 13779625
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

ID: 13779696
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

ID: 13779831
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Six Sigma Control Plans
Loops Section Overview
###### Suggested Courses
Course of the Month17 days, 17 hours left to enroll