# Constraint - Comparing two "time" questions

**URL:** <https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781>\
**Category:** Support\
**Tags:** form-design, odk-xlsform\
**Created:** [September 11, 2017, 2:19pm UTC](https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781 "2017-09-11T14:19:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guillaume.pottier](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/g/f05b48/32.png) [@guillaume.pottier](https://forum.getodk.org/u/guillaume.pottier)\
**Post date:** [September 11, 2017, 2:19pm UTC](https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781/1 "2017-09-11T14:19:30Z")

</div>

Hello everyone,

I am currently trying to implement a constraint on a form that has two time variables (opening & closing hour). I would simply like to have a constraint on the closing hour so that it can't be earlier than the opening hour.

I have tried several lines in the "constraint" cell in the Excel file but can't get it to work properly.

Do you know which constraint should I write in order to achieve this result ?

Thank you very much in advance,

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [September 11, 2017, 3:11pm UTC](https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781/2 "2017-09-11T15:11:29Z")

</div>

Hi @guillaume.pottier  
you can use this example:  
[timeConstraintTes.xlsx](https://getodk.b-cdn.net/uploads/default/original/2X/f/f0a90b6da99cdbc392e783ce365ebcb361583029.xlsx) (9.8 KB)

Let me know if it solves your problem.

Regards,  
Grzegorz

---

<div class="post-metadata">

**Author:** ![Dan](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/dan/32/7019_2.png) [@Dan](https://forum.getodk.org/u/Dan)\
**Post date:** [February 4, 2020, 7:56am UTC](https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781/3 "2020-02-04T07:56:54Z")

</div>

Hi @Grzesiek2010, I was searching for a solution to a similar problem and I am glad I bumped into this response.

I can confirm that this solves the problem.

Thank you,  
Dan

---

<div class="post-metadata">

**Author:** ![faran\_d](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/faran_d/32/19388_2.png) [@faran\_d](https://forum.getodk.org/u/faran_d)\
**Post date:** [January 25, 2023, 11:24am UTC](https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781/4 "2023-01-25T11:24:32Z")

</div>

Hi all,

@Grzesiek2010 thank you for providing the solution to this. I have tried using this same constraint, and it works perfectly in the app but for some reason it doesn't seem to work on the web version while I am testing. Please see screenshot below - no matter what time I put in the "End time" it still shows as an error.

![image](https://getodk.b-cdn.net/uploads/default/original/3X/9/0/9024af03504accd85918ac39e45d444de820b124.png)

I used the same constraint you suggested: decimal-date-time(.)\>decimal-date-time(../start\_time)

Any advice?

Many thanks,

Faran

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [January 25, 2023, 4:04pm UTC](https://forum.getodk.org/t/constraint-comparing-two-time-questions/9781/5 "2023-01-25T16:04:37Z")

</div>

`decimal-date-time()` requires a dateTime. Use `decimal-time()` instead.
