The Code below will convert a Duration (Datatype in NAV) to a Timespan i.e.
It will convert 2 days 5 hours 6 minutes 40 seconds to 2:5:6:40.
VarDuration := "Ending Date-Time" - "Starting Date-Time";
//"Ending Date-Time" and "Starting Date-Time" are DateTime fields.
VarDays := VarDuration DIV 86400000;
VarDuration := VarDuration MOD 86400000;
VarHours := VarDuration DIV 3600000;
VarDuration := VarDuration MOD 3600000;
VarMinutes := VarDuration DIV 60000;
VarDuration := VarDuration MOD 60000;
VarSeconds := VarDuration DIV 1000;
Message('%1:%2:%3:%4', VarDays, VarHours, VarMinutes, VarSeconds);
//VarDays, VarHours, VarMinutes, VarSeconds are all declared as BigInteger
//VarDuration as Duration
I tried but I wasn't able to develop or find a code online for this topic. So I thought I should create a post on it. Thanks to a fellow colleague for this code. Posting after a long time... :)
Keep Learning!
Ishwar
It will convert 2 days 5 hours 6 minutes 40 seconds to 2:5:6:40.
VarDuration := "Ending Date-Time" - "Starting Date-Time";
//"Ending Date-Time" and "Starting Date-Time" are DateTime fields.
VarDays := VarDuration DIV 86400000;
VarDuration := VarDuration MOD 86400000;
VarHours := VarDuration DIV 3600000;
VarDuration := VarDuration MOD 3600000;
VarMinutes := VarDuration DIV 60000;
VarDuration := VarDuration MOD 60000;
VarSeconds := VarDuration DIV 1000;
Message('%1:%2:%3:%4', VarDays, VarHours, VarMinutes, VarSeconds);
//VarDays, VarHours, VarMinutes, VarSeconds are all declared as BigInteger
//VarDuration as Duration
I tried but I wasn't able to develop or find a code online for this topic. So I thought I should create a post on it. Thanks to a fellow colleague for this code. Posting after a long time... :)
Keep Learning!
Ishwar