# How to calculate time with another time

#### Get our Free Newletter

Don't you have the time to be online here at DUG every day? So how do you follow what is going on in the Dynamics industry and community?
If you subscribe to the DUG Newsletter then you can relax! We will make sure that you don't miss the big news!

Check out our
page a complete list of our different newsletters.

#### This post has 1 verified solution | 8 Replies | 4 Followers

92 Posts
950 Points
Joined: 2009-7-24
Last Online:
2011-3-17 9:38
Location: Chennai,India
Seshadri posted on 2010-2-19 8:16 | Locked

Dear user,

Am doing a time calculation in navision, where am calculating a time + time, Is it possible to calculate or need exact c/Al code  for time calculation.

#### Verified Solution

1,298 Posts
28,114 Points
Joined: 2006-9-21
Last Online:
2015-5-7 13:35
Location: Delhi-India
Dhan Raj Bansal replied on 2010-2-19 8:37 | Locked
Verified by Erik P. Ernst

In this case one of the operand should be Time whereas other as integer (in MilliSeconds)..

For more details have a look on Codeunit 416 DateTime Mgmt.

For example, following code will increment the initial time defined by 1 minute (60*1000  mili seconds):

TimeCalc:=010145T;
TimeCalc:=TimeCalc+60000;
MESSAGE('%1',TimeCalc);

-Dhan Raj Bansal

• | Post Points: 105

#### All Replies

1,298 Posts
28,114 Points
Joined: 2006-9-21
Last Online:
2015-5-7 13:35
Location: Delhi-India
Dhan Raj Bansal replied on 2010-2-19 8:37 | Locked
Verified by Erik P. Ernst

In this case one of the operand should be Time whereas other as integer (in MilliSeconds)..

For more details have a look on Codeunit 416 DateTime Mgmt.

For example, following code will increment the initial time defined by 1 minute (60*1000  mili seconds):

TimeCalc:=010145T;
TimeCalc:=TimeCalc+60000;
MESSAGE('%1',TimeCalc);

-Dhan Raj Bansal

• | Post Points: 105
921 Posts
20,642 Points
Joined: 2009-10-6
Last Online:
2015-9-3 8:02
Location: Warnsveld, Netherlands
Luc van Vugt replied on 2010-2-19 9:33 | Locked

What always helps me is to realize that the Time data type is representing a time instance, like 1 o'clock. So wanting to add two time instances (two Time variables) doesn't make sense. BEcause what would the outcome of:

1:00 AM + 5:00 PM = ?

To calculate a new time instance based on a current time instance you need to add a time duration being the "integer (in MilliSeconds" Dhan Rai refers to. So the calculation is:

New Time Instance = Old Time Instance + Time Duration

or in NAV data types:

Time := Time + Integer

Hopes this makes sense.

Luc van Vugt, Imtech ICT
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community

• | Post Points: 11
909 Posts
13,604 Points
Joined: 2000-10-26
Last Online:
2015-9-3 10:41
Location: Faroe Islands
Anfinnur replied on 2010-2-19 10:14 | Locked

Luc van Vugt:
So wanting to add two time instances (two Time variables) doesn't make sense

Oh yes, it does. I have made some rathar large and timeconsuming batches, at I found it handy to know, when the batch is expected to end - an estimation. And at that time you may calc StartTime + EstimatedTimeLft = ExpectedEndTime.

Else - to calculate two times results in an integer. If you want the result in a time-datatype the formula is "ResultTime := 00T + (ActualTime - StartTime)" (00T allows type conversion from integer to time).

• | Post Points: 11
921 Posts
20,642 Points
Joined: 2009-10-6
Last Online:
2015-9-3 8:02
Location: Warnsveld, Netherlands
Luc van Vugt replied on 2010-2-19 11:52 | Locked

But that is still not adding two time instance.

StartTime + EstimatedTimeLft = ExpectedEndTime

This equation is of type:

New Time Instance = Old Time Instance + Time Duration

Luc van Vugt, Imtech ICT
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community

• | Post Points: 11
15 Posts
248 Points
Joined: 2011-4-29
Last Online:
2013-6-28 12:01
Location: CPT
Avril replied on 2012-3-30 17:52 | Locked

How do you calculate the difference between 2 time instances ? I need to get a duration, based on a starting and ending time ie

Duration = End time - Start time.

This however does not compile.

• | Post Points: 11
921 Posts
20,642 Points
Joined: 2009-10-6
Last Online:
2015-9-3 8:02
Location: Warnsveld, Netherlands
Luc van Vugt replied on 2012-3-30 17:57 | Locked

What is you exact code?

Avril:
Duration = End time - Start time

But the fact that it does not compile is probably due to soem error in the syntax of you code. So what's your code and also give the definitations of the variables included.

Luc van Vugt, Imtech ICT
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community

• | Post Points: 11
1 Posts
11 Points
Joined: 2012-12-21
Last Online:
2013-9-16 17:22
Location: Florence - Italy
Marco replied on 2012-12-21 17:31 | Locked

Hello everybody

I've to calculate a total time of a work adding two duration:

Total Time := (FinalTime1 - InitTime1) + (FinalTime2 - InitTime2). Is it possible?

What kind of types must be the variables?Is Total Time a integer in milliseconds?

Thank You so much

• | Post Points: 11
5,090 Posts
133,411 Points
Joined: 2009-2-17
Last Online:
2015-9-3 18:02