converting integer to time

ricky76ricky76 Member Posts: 204
Hi, can anyone help me? When converting an integer to a time duration and the duration is going to be greater than a day the duration doesn't show properly. For example if i have an integer value of 36000000 and convert this to a time it shows correctly as 10:00:00 as in 10 hours. However if my integer value gets to 115200000 the duration shows as 08:00:00 rather than 31:00:00. Is there an elegant way to handle this does anyone know?

Comments

  • klavinklavin Member Posts: 117
    vDuration := 36000000;
    OriginalDateTime := CURRENTDATETIME;
    vDateTime := OriginalDateTime + vDuration;
    ErrorText := 'Original DateTime : ' + FORMAT(OriginalDateTime) + '\' +
                 'Adding Duration   : ' + FORMAT(vDuration) + '\' +
                 'Result DateTime   : ' + FORMAT(vDateTime);
    
    ERROR(ErrorText);
    
    Will Result:
    Original DateTime : 12/12/09 09:56 AM
    Adding Duration : 10 hours
    Result DateTime : 12/12/09 07:56 PM

    Duration is the difference between two date times, it can be added to times, or FORMAT'ed to see the "10 Hours".

    Really, changing vDuration to 115200000 is 1 Day 8 Hours (24+8) 32 hrs. But there is no Time of 32:00:00. If you try to format that into a "Time" the time is 8. The DURATION is 32. Changing vDuration to 115200000 the Result is...

    Original DateTime : 12/12/09 09:58 AM
    Adding Duration : 1 day 8 hours
    Result DateTime : 12/13/09 05:58 PM

    You can set a Datetime to whatever you really need, but I don't understand what more you want from Duration. Duration is saying the amount of ms. 36000000 = 1000ms * 60s * 60m * 10Hr

    Lavin
    -Lavin
    "Profanity is the one language all programmers know best."
Sign In or Register to comment.