// Init all vars // vFirstDT // DATETIME // vSecondDT // DATETIME lvDuration := 0; // DECIMAL lvSeconds := 0; // DECIMAL lvMinutes := 0; // DECIMAL lvHours := 0; // DECIMAL lvDays := 0; // DECIMAL datestr := ''; // TEXT roundup := ''; // TEXT rounddown := ''; // TEXT durstr := ''; // TEXT // Set our rounding variables roundup := '>'; rounddown := '<'; // Find the duration between two DateTime objects, in milliseconds lvDuration := vSecondDT - vFirstDT; // Convert the Duration to Days, Hours, Minutes, and Seconds. Milliseconds? Fuggetaboutit! lvDuration := lvDuration / 1000; lvDays := ROUND((lvDuration / 86400), 1, rounddown); lvHours := ROUND(((lvDuration - (lvDays * 86400)) / 3600), 1, rounddown); lvMinutes := ROUND(((lvDuration - (lvDays * 86400) - (lvHours * 3600)) / 60), 1, rounddown); lvSeconds := ROUND(((lvDuration - (lvDays * 86400) - (lvHours * 3600) - (lvMinutes * 60))), 1, rounddown); // Set some output in a human-readable format datestr := FORMAT(lvDays) + 'D '; datestr := datestr + FORMAT(lvHours) + 'H '; datestr := datestr + FORMAT(lvMinutes) + 'M '; datestr := datestr + FORMAT(lvSeconds) + 'S'; // return the duration string durstr := datestr;
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
but if you get paid per line of code then its not a good solution
I wrote this because I was pretty confused by the formatting documentation and I wanted control over how my days, hours, minutes, and seconds display. Also, it seemed like others were looking for similar things but not quite getting the control they wanted.
Sam
If anyone knows or can post the FORMAT command to achieve the same output, I'd be grateful:
Like:
0D 00:00:00
Thanks!
Sam
I was joking, thus the
One thing you will find often in Navision is that you can get almost what you need maybe 99% with a couple of lines of code, but that other 1% might take another 25 lines.
I am very new to Navision, so it's good to know that more experienced users might look at this in a similar way. : )
-Sam
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!