# Setrange on a time field

**URL:** <https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445>\
**Category:** Developers Forum\
**Created:** [August 30, 2015, 1:00am UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445 "2015-08-30T01:00:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![poppins](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@poppins](https://www.dynamicsuser.net/u/poppins)\
**Post date:** [August 30, 2015, 1:00am UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/1 "2015-08-30T01:00:22Z")

</div>

|   
Hi everyone,  
I am using a custom table, among fields are “Starting time” and “Ending time” (both of type time).  
I want to add some checks to avoid overlapping between times.  
I tried to use the same code as in standard NAV table 99000752 (Shop Calendar Working Days) for validating “Starting time” and “Ending time”.  
I put the following code in a function:  
  
  
  
`recXXX.SETRANGE("Starting Time",0T,"Ending Time" - 1);`  
`recXXX.SETRANGE("Ending Time","Starting Time" + 1,235959T);`  
`IF recXXX.FINDFIRST THEN`  
`ERROR('Conflict!!!');`  
  
  
  
and called the function in the OnValidate triggers of both fields.  
The problem is that I keep getting the following error message:  
  
  
  
`The time is not valid`  
  
  
  
The debugger stops at the first instruction.  
What shall I do?  
Thanks in advance ![:mrgreen:](http://www.mibuso.com/forum/images/smilies/icon_mrgreen.gif)  
 |
| --- |

---

<div class="post-metadata">

**Author:** ![George\_Love](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@George\_Love](https://www.dynamicsuser.net/u/George_Love)\
**Post date:** [August 30, 2015, 3:18am UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/2 "2015-08-30T03:18:53Z")

</div>

Maybe try -1T instead of -1?

---

<div class="post-metadata">

**Author:** ![admin1](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/admin1/32/7476_2.png) [@admin1](https://www.dynamicsuser.net/u/admin1)\
**Post date:** [August 30, 2015, 7:27pm UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/3 "2015-08-30T19:27:01Z")

</div>

Hi Poppins,

You’ll get that error, if the “Starting Date” and “Ending Date” you use in your filter are not initiated before you add/deduct 1 from the value.

---

<div class="post-metadata">

**Author:** ![poppins](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@poppins](https://www.dynamicsuser.net/u/poppins)\
**Post date:** [August 31, 2015, 6:49pm UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/4 "2015-08-31T18:49:51Z")

</div>

> [@](#):
>
> Hi Poppins,
> 
> You’ll get that error, if the “Starting Date” and “Ending Date” you use in your filter are not initiated before you add/deduct 1 from the value.

Hi Eric,

I am not sure I understood you well but here is the total code of my function.

recYYY.SETFILTER(“Starting Time”,‘\<\> %1’,0T);

recYYY.SETFILTER(“Ending Time”,‘\<\> %1’,0T);

IF recYYY.FINDSET THEN

REPEAT

recXXX := recYYY;

recXXX .INSERT;

UNTIL recXXX .NEXT = 0;

recXXX := xRec;

IF recXXX .DELETE THEN ;

recXXX .SETRANGE(“Starting Time”,0T,“Ending Time” - 1);

recXXX .SETRANGE(“Ending Time”,“Starting Time” + 1,235959T);

IF recXXX .FINDFIRST THEN

ERROR(‘Conflict!!!’);

As I previously said, it is a copy of the standard…but still giving error…

What do I have to change?

---

<div class="post-metadata">

**Author:** ![admin1](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/admin1/32/7476_2.png) [@admin1](https://www.dynamicsuser.net/u/admin1)\
**Post date:** [September 1, 2015, 6:41am UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/5 "2015-09-01T06:41:14Z")

</div>

If you look at this line in your code:

recXXX .SETRANGE(“Starting Time”,0T,“Ending Time” - 1);

Here you specify that the “Starting Time” should use recXXX, but you do not specify which table it should take “Ending Time” from. So it will take it from the global var/table. So if this is the total of your code, then you never assign a value to “Ending Time” (as well as “Starting Time” in the following line). You never specify which record the dates are taken from. So these lines must be changed and assigned a value.

recXXX .SETRANGE(“Starting Time”,0T,WhichTableRecordAreYouTakingThisFieldFrom.“Ending Time” - 1);

---

<div class="post-metadata">

**Author:** ![admin1](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/admin1/32/7476_2.png) [@admin1](https://www.dynamicsuser.net/u/admin1)\
**Post date:** [September 1, 2015, 6:44am UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/6 "2015-09-01T06:44:38Z")

</div>

Run the code and what the Ending Date/Starting Date’s used as parameters in you setrange. Then you’ll see that they are not initiated or assigned any value.

---

<div class="post-metadata">

**Author:** ![admin1](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/admin1/32/7476_2.png) [@admin1](https://www.dynamicsuser.net/u/admin1)\
**Post date:** [September 23, 2015, 9:52pm UTC](https://www.dynamicsuser.net/t/setrange-on-a-time-field/58445/7 "2015-09-23T21:52:08Z")

</div>

Hi Poppins,

Did this help you?
