Question How To Convert Decimal Data To Time

Nellida

New Member
Hello.

I have a maintenance screen that allows the user to enter in a start time and an end time then minutes taken for a break in decimal format. (No, I didn't create this but I have to deal with it.)
I have a browse that displays this data, but now I need to somehow convert this decimal data into a time format so that I can sum the time spent for each work order.
For example: start time is 7.30, end time is 16.22 and break minutes are 50.
What I need to be displayed as the output is 8:02 which would be 8 hours and 2 minutes.
The reason the time is important is because the user then exports the browse to excel and sums up the work orders per part number to get total time spent building specific parts.

In sql server, I would be able to remove the decimal and replace it with a colon to sum the time. Is something similar available in progress or am I looking at the problem all wrong?
 

Stefan

Well-Known Member
Using the replace 'technique':
Code:
def var destart_time    as dec initial 7.30.
def var deend_time      as dec initial 16.22.
def var ibreak_minutes  as int initial 50.

message 
  string(
    interval( 
      datetime( substitute( "&1 &2", today, replace( string( deend_time  , "99.99" ), session:numeric-decimal-point, ":" ) ) ),    
      datetime( substitute( "&1 &2", today, replace( string( destart_time, "99.99" ), session:numeric-decimal-point, ":" ) ) ),
      "seconds"
     )
     - ( ibreak_minutes * 60 ),
     "hh:mm"
  )    
view-as alert-box.
Pulling the decimal apart:
Code:
def var destart_time    as dec initial 7.30.
def var deend_time      as dec initial 16.22.
def var ibreak_minutes as int initial 50.

function minutes returns int (
  i_detime as dec
):

  def var ihours   as int.
  def var iminutes as int.
 
  ihours = truncate( i_detime, 0 ). 
  iminutes = 100 * ( i_detime - ihours ).
 
  return ihours * 60 + iminutes.

end function.


message 
   string( 60 * ( minutes( deend_time ) -  minutes( destart_time ) - ibreak_minutes ), "HH:MM" )
view-as alert-box.
 
Top