How to Format Duration Data Type

james_cs
james_cs Member Posts: 39
edited 2014-05-31 in NAV Tips & Tricks
Hi.

I struggled with this one a bit so when I found the answer I thought I would post it. -mostly so that when I forget I'll find it here to remind myself!

The duration data type formats very nicely into words -
MyDuration :=  (23.4 * 60000);
MESSAGE(FORMAT(MyDuration));

gives a very nice "23 minutes 24 seconds". However, if you want to change the format there are no formatting functions for a duration. The only way to show this as 00:23:24 is to convert it into a DateTime variable and format that
MyDateTime := CREATEDATETIME(TODAY,0T);
MyDateTime += MyDuration;
MESSAGE(FORMAT(MyDateTime,0,'<Hours24,2>:<Minutes,2>:<Seconds,2>'));

I hope this helps.

Comments

  • einsTeIn.NET
    einsTeIn.NET Member Posts: 1,050
    I think your idea is clear but you can achieve this much easier.
    MESSAGE('%1',000000T + myDuration);
    
    And what will happen if the duration reaches the 24 hours range? You see this isn't a one-size-fits-all solution. It depends on the current needs of someone if this could be used.
    "Money is likewise the greatest chance and the greatest scourge of mankind."