# Undefined Time

**URL:** <https://www.dynamicsuser.net/t/undefined-time/5267>\
**Category:** Developers Forum\
**Created:** [August 13, 2001, 10:59am UTC](https://www.dynamicsuser.net/t/undefined-time/5267 "2001-08-13T10:59:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanWeinreich](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@StefanWeinreich](https://www.dynamicsuser.net/u/StefanWeinreich)\
**Post date:** [August 13, 2001, 10:59am UTC](https://www.dynamicsuser.net/t/undefined-time/5267/1 "2001-08-13T10:59:17Z")

</div>

I need to compare a time-field with the actual time less 90 minutes. The code i created was IF (tab2.“End time” \< (TIME - 5400000)) THEN BEGIN Compiling the code shows no error, but when i try to execute the report i always get the error message ‘An undefined time can’t be used in time calculation’. Going back into the report the word TIME is always converted to ‘Time’. Using a variable like NewTime := TIME; NewTime := NewTime - 5400000; doesn’t solve the problem. How can i calculate the time correctly ?? Stefan Weinreich Billing Analyst

---

<div class="post-metadata">

**Author:** ![Taj](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@Taj](https://www.dynamicsuser.net/u/Taj)\
**Post date:** [August 13, 2001, 12:24pm UTC](https://www.dynamicsuser.net/t/undefined-time/5267/2 "2001-08-13T12:24:43Z")

</div>

stefan, ur code works fine. I just created a table with 2 fields with starttime as one of field with data type as Time. in Onvalidate() of Starttime field I just wrote ur condition… IF (Starttime \< (TIME - 5400000)) THEN MESSAGE(‘Time is less than 90 mins Less Current time’) ELSE MESSAGE(‘Time is greater than or equal to 90 mins Less Current time’); Taj

---

<div class="post-metadata">

**Author:** ![StefanWeinreich](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@StefanWeinreich](https://www.dynamicsuser.net/u/StefanWeinreich)\
**Post date:** [August 13, 2001, 12:46pm UTC](https://www.dynamicsuser.net/t/undefined-time/5267/3 "2001-08-13T12:46:53Z")

</div>

Hey Taj, odd… before i posted my problem i created a little report with just a single line: MESSAGE(‘current time is %1\calculated time is %2’, TIME, (TIME - 5400000)); this worked fine, but when i use the code shown above i get the error message. Perhaps there has something been changed in our version (DE 2.50) ? Stefan Weinreich Billing Analyst

---

<div class="post-metadata">

**Author:** ![wex](https://avatars.discourse-cdn.com/v4/letter/w/e9c0ed/32.png) [@wex](https://www.dynamicsuser.net/u/wex)\
**Post date:** [August 13, 2001, 3:06pm UTC](https://www.dynamicsuser.net/t/undefined-time/5267/4 "2001-08-13T15:06:47Z")

</div>

Stefan, I can reproduce your problem: In table Tab2 there is a field called ‘Time’. The code looks like this: With Tab2 do IF “End Time” \< (Time - 5400000) THEN … (This also explains the conversion from TIME to Time). If this is your problem, you should rename the field called Time in your Table Tab2. Willy

---

<div class="post-metadata">

**Author:** ![StefanWeinreich](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@StefanWeinreich](https://www.dynamicsuser.net/u/StefanWeinreich)\
**Post date:** [August 13, 2001, 3:36pm UTC](https://www.dynamicsuser.net/t/undefined-time/5267/5 "2001-08-13T15:36:28Z")

</div>

Hey Willy, yes, you’re right. There was a field called “Time”. Setting the “EndTime” Variable as global and initialising it during the report-init-phase everything worked fine. thanks a lot ! Stefan Weinreich Billing Analyst

---

<div class="post-metadata">

**Author:** ![fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@fabian](https://www.dynamicsuser.net/u/fabian)\
**Post date:** [August 14, 2001, 12:29am UTC](https://www.dynamicsuser.net/t/undefined-time/5267/6 "2001-08-14T00:29:00Z")

</div>

Attention ! The Code line

```auto
IF (Starttime < (TIME - 5400000)) THEN

```

will not work if TIME is exactly 5400000! In this case the right bracket would be reduced to

```auto
IF (Starttime < (0)) THEN

```

And Navision will complain that it cannot compare Starttime with an undefined Time Value (Zero). If you want to use Time Arithmetic it’s a good Idea to convert the time into a decimal and vice-versa:

```auto
Function TimeToDecimal (T : Time) D : Decimal;

BEGIN
  IF T = 0T THEN
    EXIT(0.0);
  d := T- 000001T + 1000.0;
  EXIT(d / 3600000);
END;

Function DecimalToTime (d : Decimal) T : Time;

BEGIN
  IF T = 0T THEN
    EXIT(0.0);
  d := T- 000001T + 1000.0;
  EXIT(d / 3600000);
END;

```

As you can see I avoid the Time=Zero-Problem by adding and subtracting one Second. ------- With best regards from Switzerland _ **Marcus Fabian** _ Edited by - fabian on 2001 Aug 14 01:29:31

---

<div class="post-metadata">

**Author:** ![StefanWeinreich](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@StefanWeinreich](https://www.dynamicsuser.net/u/StefanWeinreich)\
**Post date:** [August 14, 2001, 8:16am UTC](https://www.dynamicsuser.net/t/undefined-time/5267/7 "2001-08-14T08:16:01Z")

</div>

I’ve just tried what happens, if TIME - 5400000 results in a value (or time) less 0. There the time was correctly converted in the new 24hours-time (21:59:03 or something else). Normally 0:00 is a valid time. So if you’re right (i didn’t check this yet) the system couldn’t handle midnight (0:00) ?! Stefan Weinreich Billing Analyst

---

<div class="post-metadata">

**Author:** ![fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@fabian](https://www.dynamicsuser.net/u/fabian)\
**Post date:** [August 15, 2001, 2:46am UTC](https://www.dynamicsuser.net/t/undefined-time/5267/8 "2001-08-15T02:46:23Z")

</div>

Quite correct. To be precise: The system cannot handle midnight if the Time is used in time-calculations. Now, coming back to your example with 90 minutes or 5’400’000 Milliseconds: Let’s assume you have a job which should break after 90 Minutes maximum execution time:

```auto

StartTime := TIME;
REPEAT
UNTIL (Finished) or ((TIME - 5400000) > StartTime)

```

You might end up in troubles if the job exceeds midnight respectively any time between midnight and 1:30 as the result of (TIME- 5400000) will always be negative and therefore be smaller than StartTime which is \>=0 You could however change

```auto
((TIME - 5400000) > StartTime) 

```

into the positive Range using

```auto
((StartTime + 5400000) < Time) 

```

and take the change to the next day into consideration:

```auto
IF ((StartTime + 5400000) < Time) OR
(Today > StartDate)

```

------- With best regards from Switzerland _ **Marcus Fabian** _
