How to format duration type variable?

arcullarcull Member Posts: 191
edited 2009-07-22 in Navision Attain
Hi there. Anyone maybe knows how to format duration. I have the case where duration is difference between two datetimes, and would like to have displayed just days and hours, without minutes and seconds. Thanks for any suggestion.

Comments

  • reijermolenaarreijermolenaar Member Posts: 256
    Hi Arcull,

    You can use the round function.

    To remove the milliseconds:
    Duration2 := ROUND(DateTime1 - DateTime2, 1000);
    

    To remove the millisecond and seconds:
    Duration2 := ROUND(DateTime1 - DateTime2, 1000 * 60);
    
    Reijer Molenaar
    Object Manager
  • reijermolenaarreijermolenaar Member Posts: 256
    I see that you asked for removing the minutes also:
    Duration2 := ROUND(DateTime1 - DateTime2, 1000 * 60 * 60);
    
    Reijer Molenaar
    Object Manager
  • arcullarcull Member Posts: 191
    thanks reijermolenaar, It seems there is no other option but treating duration as integer and calculating time units from it, thanks again.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Just convert it to a Date Time and then just use Standard Navision formatting if its just for display then there is no need to round.
    David Singleton
  • reijermolenaarreijermolenaar Member Posts: 256
    Hi David,

    Can you please give an example how to do that.
    I cannot find these options in the help texts.

    What expression do you use if you want to display it e.g. like this:
    "12 days 3 hours 14 minutes"?
    Reijer Molenaar
    Object Manager
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Hi David,

    Can you please give an example how to do that.
    I cannot find these options in the help texts.

    What expression do you use if you want to display it e.g. like this:
    "12 days 3 hours 14 minutes"?

    Try F1 on the FORMAT function. :wink:
    David Singleton
  • reijermolenaarreijermolenaar Member Posts: 256
    I already did that and the options for day/days and hour/hours are not available.
    So if you want to display your duration in full text you cannot convert it to Date Time? :-k

    Or am I something missing here?
    Reijer Molenaar
    Object Manager
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Well since you have given virtually no information about what you are trying to do I can only guess, but something like

    '<Days,2> days <Hours,24> hours <minutes,2> minutes'

    I guess.
    David Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    I am starting to wonder if maybe F1 does not work in many country versions of Navision. ](*,)
    David Singleton
  • reijermolenaarreijermolenaar Member Posts: 256
    F1 is working fine in the Netherlands! :D

    As I said, there is no option for the days and minutes part in the format parameters.
    You pass them as fixed text.

    So how you handle plural like day/days?
    And what about translation? NLD: Dagen ENU: Days

    If you do a FORMAT(duration) NAV handles all these things.
    If you convert to a datetime variable you lose all this functionality.
    Reijer Molenaar
    Object Manager
Sign In or Register to comment.