Convert Decimal To Duration

ricky76ricky76 Member Posts: 204
Any one if this is possible and if so how to do it?

Comments

  • rvduurenrvduuren Member Posts: 92
    Hello ricky76,

    Try :
    Name >DataType
    Dur > Duration
    Dec > Decimal
    ----------------------------------
    Dec := 22;
    EVALUATE(Dur,FORMAT(Dec));
    message('%1',Dur);
    
    The answer of the message is :: "22 hours"

    Let me know if this is what you mean..
    Met vriendelijke groet, best regards,

    Rvduuren
  • ricky76ricky76 Member Posts: 204
    Thank you very much rvduuren that's perfect. Just another quick question. If the duration is over one day it displays as 1 day 2 hours etc. Is there a way i can display this as 26 hours?
  • rvduurenrvduuren Member Posts: 92
    Hello Ricky,

    Try:
    Globals
    Name > DataType
    Dur > Duration	
    BigInt > BigInteger
    -----------------------------
    EVALUATE(Dur,'26');
    BigInt := Dur;
    message('%1 Hour',BigInt/3600000);
    
    The answer of the message is :: "26 hours"
    C/Al Help >>
    BIGINTEGER
    Use this data type to store very large whole numbers. This data type is a 64 bit integer. You must add an L to the constant definition to inform C/AL that the integer must be interpreted and treated as a BIGINTEGER.

    DURATION
    Use this data type to represent the difference between two datetimes, in milliseconds. This value can be negative. It is a 64 bit integer.
    DATETIME-DATETIME=DURATION
    DATETIME-DURATION=DATETIME
    DATETIME+DURATION=DATETIME
    I hope this is useful for you, let me know..
    Met vriendelijke groet, best regards,

    Rvduuren
  • ricky76ricky76 Member Posts: 204
    Everything is going fine now thanks just one more problem. I have a datetime field that looks at the time someone clocks in. If they clock in before 6:00 the report needs to identify this and put 6:00 rather than the time they clocked in at. Any ideas?
  • kinekine Member Posts: 12,562
    You can use DT2TIME and DT2DATE to split the DT to DATE and TIME. After that you can test the time, correct it to 6:00 if needed and reconstruct the DT with CREATEDATETIME...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ricky76ricky76 Member Posts: 204
    Ok i am fine to this point but how do i do the test against the time part?
  • ara3nara3n Member Posts: 9,256
    if myTime < 1400T then
    myTime := 1400T
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ricky76ricky76 Member Posts: 204
    Thank you kindly folks.
  • mickukmickuk Member Posts: 47
    Hi Guys,

    I'm looking for a little bit of clarification on the above. I've looked through the application designers guide and the Navision Financials Help and I'm a little stuck..

    I understand what is explained above, however how would one do a comparison of two times and obtain a decimal representation in hours? For example:

    StartTime := 0900T;
    EndTime := 1500T;

    So the difference should be 6 hours. I've done something very similar in Excel but im not that familiar with the date & time functions that are available within Navision.

    Excel Formula

    (C8-C7+(C8<C7))*24

    C8 = EndTime
    C7 = StartTime

    So using the above would be as follows:

    C8 would equate to 0.625
    C7 would equate to 0.375

    Which would equal 0.25. In this instance the EndTime is not less than the StartTime so we then multiply the first part of the equation (0.25) by 24 giving the answer of 6 hours.

    Hope i make sense?
  • kinekine Member Posts: 12,562
    One tip: In Navision, when you subtract time variables, result is integer representing the duration in milliseconds.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mickukmickuk Member Posts: 47
    Thanks very much for the advice! I should have really noticed from the above info #-o

    I think this might help a few other people that come across this, especially if they dont have a lot of coding experience with Navision like myself.
  • jlettjlett Member Posts: 9
    If you have time1 and time2 and want then result time3=time2-time1, how to do ?
    NB : no get on message but in a variable time3
  • kinekine Member Posts: 12,562
    You can try something like:
    time3 := 0T + (Time1 - Time2);
    

    but you must be sure that the time2 < time1.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.