Options

Convert a text into duration type?

undy0602undy0602 Member Posts: 67
Hello experts,
I need import text file into NAV using XMLport. Duration format is below text type. But duration has another format in NAV. How can I convert a text data into duration type?
Example:
text is '00:08:06:07' -> duration:8 min 6 sec 7milsec

Regards,
Undy

Answers

  • Options
    AlbertvhAlbertvh Member Posts: 516
    Hi
    Have you tried the EVALUATE statement
  • Options
    undy0602undy0602 Member Posts: 67
    Yes, tried. There are two options to check this on the below.
    DurVal is:00:08:09:07

    First:
    AllText:=COPYSTR(DurVal,1,2)+COPYSTR(DurVal,4,2)+COPYSTR(DurVal,7,2)+COPYSTR(DurVal,10,2);
    EVALUATE(All,AllText);
    MESSAGE('%1',All);
    Result is: 3371 days 3 hours

    Second:
    hourText:=COPYSTR(DurVal ,1,2)
    EVALUATE(hour,hourText);
    MinText:=COPYSTR(DurVal ,4,2);
    EVALUATE(min,MinText);
    SecText:=COPYSTR(DurVal ,7,2);
    EVALUATE(sec,secText);
    MSecText:=COPYSTR(DurVal ,10,2);
    EVALUATE(Msec,MsecText);
    MESSAGE('%1, %2 , %3 , %4 ',hour,min,sec,MSec);
    results is: , 8 hours , 9 hours , 7 hours

    I want to insert a DurVal into NAV table. How can I solve it?

    Best Regards,
    Undy
  • Options
    JonasAJonasA Member Posts: 28
    edited 2015-12-11
    I believe that you can just convert it yourself.
    Duration is just a number.
    Represents the difference between two DateTimes. This value can be negative. It is stored as a 64-bit integer. The integer value is the number of milliseconds during the duration.

    Since you split the value, you can just do the following (The magic numbers are just conversion to milliseconds):
    Hours := 5;
    Minutes := 8;
    Seconds := 6;
    MilliSeconds := 7;
    
    Duration := Duration + Hours * 3600000;
    Duration := Duration + Minutes * 60000;
    Duration := Duration + Seconds * 1000;
    Duration := Duration + MilliSeconds;
    
    MESSAGE(FORMAT(Duration));
    

    Hope this helps
  • Options
    undy0602undy0602 Member Posts: 67
    Thanks JonasA,
    It helps a lot :)
Sign In or Register to comment.