duration to time

kanikakanika Posts: 227Member
Hi Experts!!
I have a field type duration with value 1132690
I want to pass it to type time 00:00 h. but I can not find any function that does, only text with the format function but that is not what I need, is there any function?

As always thank you very much

Best Answer

Answers

  • DuikmeesterDuikmeester Hoorn, The NetherlandsPosts: 296Member
    edited 2019-01-08
    aBigInteger := theDurationValue;
    
    aHours := ROUND(aBigInteger / 3600000,1,'<'); //60 minutes in a hour * 60 seconds in a minute * 1000 milliseconds in a second
    aBigInteger := aBigInteger MOD 3600000;
    
    aMinutes := ROUND(aBigInteger / 60000,1,'<'); //60 seconds in a minute * 1000 milliseconds in a second
    aBigInteger := aBigInteger MOD 60000;
    
    aSeconds := ROUND(aBigInteger / 1000,1,'<'); //1000 milliseconds in a second
    aBigInteger := aBigInteger MOD 1000;
    
    aFractions := ROUND(aBigInteger / 10,1,'<');
    
    aValue := FORMAT(aHours,0,'<Integer,2><Filler Character,0>') + ':' +
              FORMAT(aMinutes,0,'<Integer,2><Filler Character,0>') + ' h';
    
  • kanikakanika Posts: 227Member
    Thanks!! duikmeester,
    Then to create the time would be:

    MyTime: = aHoursaMinutesT;

    Can it be like this?

    I need the data in time type to do calculations do not serve me in text
  • kanikakanika Posts: 227Member
    Thank you so much!!
  • BlackTigerBlackTiger Posts: 1,225Member
    DateTimeValue := 0DT + DurationValue;
    
    "You can’t just ask customers what they want and then try to give that to them.
    By the time you get it built, they’ll want something new.” Steve Jobs
  • vaprogvaprog Posts: 892Member
    BlackTiger wrote: »
    DateTimeValue := 0DT + DurationValue;
    

    This will give you a runtime error
    The date is not valid.

    But
    TimeValue := 000000T + DurationValue;
    
    will give you a time value, which, properly formatted, might serve you as a base for displaying as duration provided the duration is short enough (i.e. depending on your time format shorter than 12 or 24 hours). You probably still would need a custom format string to format it sensibly in order to show it, for example, in a column of a table.

    Note: 0T gives you an undefined time, 000000T gives you the start of a day.
  • kanikakanika Posts: 227Member
    Thank you so much!!
Sign In or Register to comment.