# Calculate on date types

**URL:** <https://forum.getodk.org/t/calculate-on-date-types/4345>\
**Category:** Support\
**Created:** [May 15, 2015, 2:17pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345 "2015-05-15T14:17:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/colin/32/5636_2.png) [@Colin](https://forum.getodk.org/u/Colin)\
**Post date:** [May 15, 2015, 2:17pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/1 "2015-05-15T14:17:41Z")

</div>

Hi all,

I'd like to display a field to the user:  
Clinic information within 12 months of clinic enrolment (between and XXX)

I would the XXX to be ENRDT + 12 months.

I have tried using a calculate, eg  
XXX =

but this is a bit of a shot in the dark (esp that + 12, heh).

There is probably also a cleaner way to do this (eg can I manipulate the content of an field?)

Suggestions are welcome, and thanks in advance,  
Colin

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [May 15, 2015, 4:58pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/2 "2015-05-15T16:58:24Z")

</div>

There are various date-time functions available:

> **[Form Logic](https://docs.getodk.org/form-logic/)**
>
> ODK Collect supports a wide range of dynamic form behavior. This document covers how to specify this behavior in your XLSForm definition. Form logic building blocks: Variables: Variables reference ...

e.g., decimal-date().

Note, however, that there are numerous bugs/issues with date-time  
arithmetic and getting the logic to respect and preserve the time portion  
of the date-time.

Carefully test to ensure that what you write actually works.

> **···**
>
> On Fri, May 15, 2015 at 7:17 AM, wrote:
> 
> > Hi all,
> > 
> > I'd like to display a field to the user:  
> > Clinic information within 12 months of clinic enrolment (between and XXX)
> > 
> > I would the XXX to be ENRDT + 12 months.
> > 
> > I have tried using a calculate, eg  
> > XXX =
> > 
> > but this is a bit of a shot in the dark (esp that + 12, heh).
> > 
> > There is probably also a cleaner way to do this (eg can I manipulate the  
> > content of an field?)
> > 
> > Suggestions are welcome, and thanks in advance,  
> > Colin
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)

---

<div class="post-metadata">

**Author:** ![Colin](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/colin/32/5636_2.png) [@Colin](https://forum.getodk.org/u/Colin)\
**Post date:** [May 15, 2015, 6:15pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/3 "2015-05-15T18:15:00Z")

</div>

> There are various date-time functions available: [https://opendatakit.org/help/form-design/binding/](https://opendatakit.org/help/form-design/binding/)
> 
> e.g., decimal-date().
> 
> Note, however, that there are numerous bugs/issues with date-time arithmetic and getting the logic to respect and preserve the time portion of the date-time.
> 
> Carefully test to ensure that what you write actually works.
> 
> Hi all,
> 
> I'd like to display a field to the user:
> 
> Clinic information within 12 months of clinic enrolment (between and XXX)
> 
> I would the XXX to be ENRDT + 12 months.
> 
> I have tried using a calculate, eg
> 
> XXX =
> 
> but this is a bit of a shot in the dark (esp that + 12, heh).
> 
> There is probably also a cleaner way to do this (eg can I manipulate the content of an field?)
> 
> Suggestions are welcome, and thanks in advance,
> 
> Colin
> 
> --
> 
> --
> 
> Post: [opend...@googlegroups.com](mailto:opend...@googlegroups.com)
> 
> Unsubscribe: [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com)
> 
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com).
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --
> 
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitche...@gmail.com](mailto:mitche...@gmail.com)

Durr... don't know how I missed that. Thanks Mitch

> **···**
>
> On Friday, May 15, 2015 at 12:58:27 PM UTC-4, Mitch Sundt wrote: \> On Fri, May 15, 2015 at 7:17 AM, wrote:

---

<div class="post-metadata">

**Author:** ![Jan\_Priebe](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@Jan\_Priebe](https://forum.getodk.org/u/Jan_Priebe)\
**Post date:** [June 4, 2015, 10:07am UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/4 "2015-06-04T10:07:43Z")

</div>

> There are various date-time functions available: [https://opendatakit.org/help/form-design/binding/](https://opendatakit.org/help/form-design/binding/)
> 
> e.g., decimal-date().
> 
> Note, however, that there are numerous bugs/issues with date-time arithmetic and getting the logic to respect and preserve the time portion of the date-time.
> 
> Carefully test to ensure that what you write actually works.
> 
> Hi,

I'm trying to write a simple formula to check whether occurs a date X occurs at least 3 months after date Y, and if not, return a warning message.

To do this I have created a note that only shows when this condition is not met.

I have tried this using an XLSForm that is then uploaded to KoboToolbox

Relevant field: decimal-date(${dateX}) - decimal-date(${dateY}) \> '90'

I have also tried putting the constraint directly in the XML file to upload to ODK aggregate:

" decimal-date(dateX) - decimal-date(dateY) \> '90'"

in both cases I receive the error: " XPath evaluation: cannot handle function 'decimal-date' "

This sounds like decimal-date isn't accepted at all as a function, though the previous post suggest it is/should be.

Would appreciate any thoughts on this

Thanks

Jan

> **···**
>
> On Friday, May 15, 2015 at 5:58:27 PM UTC+1, Mitch Sundt wrote:
> 
> > On Fri, May 15, 2015 at 7:17 AM, [colind...@gmail.com](mailto:colind...@gmail.com) wrote:  
> > Hi all,
> > 
> > I'd like to display a field to the user:
> > 
> > Clinic information within 12 months of clinic enrolment (between and XXX)
> > 
> > I would the XXX to be ENRDT + 12 months.
> > 
> > I have tried using a calculate, eg
> > 
> > XXX =
> > 
> > but this is a bit of a shot in the dark (esp that + 12, heh).
> > 
> > There is probably also a cleaner way to do this (eg can I manipulate the content of an field?)
> > 
> > Suggestions are welcome, and thanks in advance,
> > 
> > Colin
> > 
> > --
> > 
> > --
> > 
> > Post: [opend...@googlegroups.com](mailto:opend...@googlegroups.com)
> > 
> > Unsubscribe: [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com)
> > 
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups "ODK Community" group.
> > 
> > To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com).
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --
> > 
> > Mitch Sundt  
> > Software Engineer  
> > University of Washington  
> > [mitche...@gmail.com](mailto:mitche...@gmail.com)

---

<div class="post-metadata">

**Author:** ![Colin](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/colin/32/5636_2.png) [@Colin](https://forum.getodk.org/u/Colin)\
**Post date:** [June 4, 2015, 5:41pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/5 "2015-06-04T17:41:13Z")

</div>

I was also unable to get decimal-date to work correctly.

However, I believe I have an approach that could work for your issue... you can perform basic math functions on date objects in ODK. That is, you can use div, -, etc (as well as \> and \<).

Snippet of my code:  
constraint = ( (((. - /data/ENROLDT) div 365.25) \>= 1)

So, extrapolating from that, you might try something like:  
((${dateX} - ${dateY}) div 365.25) \> 1/4  
Or, more human readably  
((${dateX} - ${dateY}) div 30) \> 3

> **···**
>
> On Thursday, June 4, 2015 at 1:13:46 PM UTC-4, jan.p...@gmail.com wrote: \> On Friday, May 15, 2015 at 5:58:27 PM UTC+1, Mitch Sundt wrote: \> \> There are various date-time functions available: https://opendatakit.org/help/form-design/binding/ \> \> \> \> e.g., decimal-date(). \> \> \> \> Note, however, that there are numerous bugs/issues with date-time arithmetic and getting the logic to respect and preserve the time portion of the date-time. \> \> \> \> Carefully test to ensure that what you write actually works. \> \> \> \> Hi, \> \> I'm trying to write a simple formula to check whether occurs a date X occurs at least 3 months after date Y, and if not, return a warning message. \> \> To do this I have created a note that only shows when this condition is not met. \> \> I have tried this using an XLSForm that is then uploaded to KoboToolbox \> \> Relevant field: decimal-date(${dateX}) - decimal-date(${dateY}) \> '90' \> \> I have also tried putting the constraint directly in the XML file to upload to ODK aggregate: \> \> " decimal-date(dateX) - decimal-date(dateY) \> '90'" \> \> in both cases I receive the error: " XPath evaluation: cannot handle function 'decimal-date' " \> \> This sounds like decimal-date isn't accepted at all as a function, though the previous post suggest it is/should be. \> \> Would appreciate any thoughts on this \> \> Thanks \> \> Jan \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> \> On Fri, May 15, 2015 at 7:17 AM, wrote: \> \> Hi all, \> \> \> \> \> \> \> \> I'd like to display a field to the user: \> \> \> \> Clinic information within 12 months of clinic enrolment (between and XXX) \> \> \> \> \> \> \> \> I would the XXX to be ENRDT + 12 months. \> \> \> \> \> \> \> \> \> \> \> \> I have tried using a calculate, eg \> \> \> \> XXX = \> \> \> \> \> \> \> \> \> \> \> \> but this is a bit of a shot in the dark (esp that + 12, heh). \> \> \> \> \> \> \> \> There is probably also a cleaner way to do this (eg can I manipulate the content of an field?) \> \> \> \> \> \> \> \> Suggestions are welcome, and thanks in advance, \> \> \> \> Colin \> \> \> \> \> \> \> \> -- \> \> \> \> -- \> \> \> \> Post: opend...@googlegroups.com \> \> \> \> Unsubscribe: opendatakit...@googlegroups.com \> \> \> \> Options: http://groups.google.com/group/opendatakit?hl=en \> \> \> \> \> \> \> \> --- \> \> \> \> You received this message because you are subscribed to the Google Groups "ODK Community" group. \> \> \> \> To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit...@googlegroups.com. \> \> \> \> For more options, visit https://groups.google.com/d/optout. \> \> \> \> \> \> \> \> \> \> -- \> \> \> \> Mitch Sundt \> \> Software Engineer \> \> University of Washington \> \> mitche...@gmail.com

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [June 4, 2015, 9:44pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/6 "2015-06-04T21:44:38Z")

</div>

Oops. My mistake.

The name of the function is:

decimal-date-time()

there is no decimal-date() function.

> **···**
>
> On Thu, Jun 4, 2015 at 10:41 AM, wrote:
> 
> > I was also unable to get decimal-date to work correctly.
> > 
> > However, I believe I have an approach that could work for your issue...  
> > you can perform basic math functions on date objects in ODK. That is, you  
> > can use div, -, etc (as well as \> and \<).
> > 
> > Snippet of my code:  
> > constraint = ( (((. - /data/ENROLDT) div 365.25) \>= 1)
> > 
> > So, extrapolating from that, you might try something like:  
> > ((${dateX} - ${dateY}) div 365.25) \> 1/4  
> > Or, more human readably  
> > ((${dateX} - ${dateY}) div 30) \> 3
> > 
> > On Thursday, June 4, 2015 at 1:13:46 PM UTC-4, [jan.p...@gmail.com](mailto:jan.p...@gmail.com) wrote:
> > 
> > > On Friday, May 15, 2015 at 5:58:27 PM UTC+1, Mitch Sundt wrote:
> > > 
> > > > There are various date-time functions available:  
> > > > [https://opendatakit.org/help/form-design/binding/](https://opendatakit.org/help/form-design/binding/)
> > > > 
> > > > e.g., decimal-date().
> > > > 
> > > > Note, however, that there are numerous bugs/issues with date-time  
> > > > arithmetic and getting the logic to respect and preserve the time portion  
> > > > of the date-time.
> > > > 
> > > > Carefully test to ensure that what you write actually works.
> > > > 
> > > > Hi,
> > > 
> > > I'm trying to write a simple formula to check whether occurs a date X  
> > > occurs at least 3 months after date Y, and if not, return a warning message.
> > > 
> > > To do this I have created a note that only shows when this condition is  
> > > not met.
> > > 
> > > I have tried this using an XLSForm that is then uploaded to KoboToolbox
> > > 
> > > Relevant field: decimal-date(${dateX}) - decimal-date(${dateY}) \> '90'
> > > 
> > > I have also tried putting the constraint directly in the XML file to  
> > > upload to ODK aggregate:
> > > 
> > > " decimal-date(dateX) - decimal-date(dateY) \> '90'"
> > > 
> > > in both cases I receive the error: " XPath evaluation: cannot handle  
> > > function 'decimal-date' "
> > > 
> > > This sounds like decimal-date isn't accepted at all as a function,  
> > > though the previous post suggest it is/should be.
> > > 
> > > Would appreciate any thoughts on this
> > > 
> > > Thanks
> > > 
> > > Jan
> > > 
> > > > On Fri, May 15, 2015 at 7:17 AM, [colind...@gmail.com](mailto:colind...@gmail.com) wrote:  
> > > > Hi all,
> > > > 
> > > > I'd like to display a field to the user:
> > > > 
> > > > Clinic information within 12 months of clinic enrolment (between  
> > > > and XXX)
> > > > 
> > > > I would the XXX to be ENRDT + 12 months.
> > > > 
> > > > I have tried using a calculate, eg
> > > > 
> > > > XXX =
> > > > 
> > > > but this is a bit of a shot in the dark (esp that + 12, heh).
> > > > 
> > > > There is probably also a cleaner way to do this (eg can I manipulate  
> > > > the content of an field?)
> > > > 
> > > > Suggestions are welcome, and thanks in advance,
> > > > 
> > > > Colin
> > > > 
> > > > --
> > > > 
> > > > --
> > > > 
> > > > Post: [opend...@googlegroups.com](mailto:opend...@googlegroups.com)
> > > > 
> > > > Unsubscribe: [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com)
> > > > 
> > > > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > > > 
> > > > * * *
> > > > 
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "ODK Community" group.
> > > > 
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --
> > > > 
> > > > Mitch Sundt  
> > > > Software Engineer  
> > > > University of Washington  
> > > > [mitche...@gmail.com](mailto:mitche...@gmail.com)
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)

---

<div class="post-metadata">

**Author:** ![Jan\_Priebe](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@Jan\_Priebe](https://forum.getodk.org/u/Jan_Priebe)\
**Post date:** [June 5, 2015, 9:06am UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/7 "2015-06-05T09:06:09Z")

</div>

Thanks both!

Mitch, no worries- I really should have just tried that myself.

Colin, thanks for the tip, I didn’t realise I could use dates in math functions without having to convert them first – problem solved!

> **···**
>
> From: opendatakit@googlegroups.com [mailto:opendatakit@googlegroups.com] On Behalf Of Mitch Sundt Sent: 04 June 2015 22:45 To: ODK Community Subject: Re: [ODK Community] Calculate on date types
> 
> Oops. My mistake.
> 
> The name of the function is:
> 
> decimal-date-time()
> 
> there is no decimal-date() function.
> 
> On Thu, Jun 4, 2015 at 10:41 AM, [colindmccann@gmail.com](mailto:colindmccann@gmail.com) wrote:
> 
> I was also unable to get decimal-date to work correctly.
> 
> However, I believe I have an approach that could work for your issue... you can perform basic math functions on date objects in ODK. That is, you can use div, -, etc (as well as \> and \<).
> 
> Snippet of my code:  
> constraint = ( (((. - /data/ENROLDT) div 365.25) \>= 1)
> 
> So, extrapolating from that, you might try something like:  
> ((${dateX} - ${dateY}) div 365.25) \> 1/4  
> Or, more human readably  
> ((${dateX} - ${dateY}) div 30) \> 3
> 
> On Thursday, June 4, 2015 at 1:13:46 PM UTC-4, [jan.p...@gmail.com](mailto:jan.p...@gmail.com) wrote:
> 
> > On Friday, May 15, 2015 at 5:58:27 PM UTC+1, Mitch Sundt wrote:
> > 
> > > There are various date-time functions available: [https://opendatakit.org/help/form-design/binding/](https://opendatakit.org/help/form-design/binding/)
> > > 
> > > e.g., decimal-date().
> > > 
> > > Note, however, that there are numerous bugs/issues with date-time arithmetic and getting the logic to respect and preserve the time portion of the date-time.
> > > 
> > > Carefully test to ensure that what you write actually works.
> > > 
> > > Hi,
> > 
> > I'm trying to write a simple formula to check whether occurs a date X occurs at least 3 months after date Y, and if not, return a warning message.
> > 
> > To do this I have created a note that only shows when this condition is not met.
> > 
> > I have tried this using an XLSForm that is then uploaded to KoboToolbox
> > 
> > Relevant field: decimal-date(${dateX}) - decimal-date(${dateY}) \> '90'
> > 
> > I have also tried putting the constraint directly in the XML file to upload to ODK aggregate:
> > 
> > " decimal-date(dateX) - decimal-date(dateY) \> '90'"
> > 
> > in both cases I receive the error: " XPath evaluation: cannot handle function 'decimal-date' "
> > 
> > This sounds like decimal-date isn't accepted at all as a function, though the previous post suggest it is/should be.
> > 
> > Would appreciate any thoughts on this
> > 
> > Thanks
> > 
> > Jan
> > 
> > > On Fri, May 15, 2015 at 7:17 AM, [colind...@gmail.com](mailto:colind...@gmail.com) wrote:  
> > > Hi all,
> > > 
> > > I'd like to display a field to the user:
> > > 
> > > Clinic information within 12 months of clinic enrolment (between and XXX)
> > > 
> > > I would the XXX to be ENRDT + 12 months.
> > > 
> > > I have tried using a calculate, eg
> > > 
> > > XXX =
> > > 
> > > but this is a bit of a shot in the dark (esp that + 12, heh).
> > > 
> > > There is probably also a cleaner way to do this (eg can I manipulate the content of an field?)
> > > 
> > > Suggestions are welcome, and thanks in advance,
> > > 
> > > Colin
> > > 
> > > --
> > > 
> > > --
> > > 
> > > Post: [opend...@googlegroups.com](mailto:opend...@googlegroups.com)
> > > 
> > > Unsubscribe: [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com)
> > > 
> > > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > > 
> > > * * *
> > > 
> > > You received this message because you are subscribed to the Google Groups "ODK Community" group.
> > > 
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --
> > > 
> > > Mitch Sundt  
> > > Software Engineer  
> > > University of Washington  
> > > [mitche...@gmail.com](mailto:mitche...@gmail.com)
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com) [mailto:opendatakit%2Bunsubscribe@googlegroups.com](mailto:opendatakit%2Bunsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to the Google Groups "ODK Community" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com) [mailto:opendatakit%2Bunsubscribe@googlegroups.com](mailto:opendatakit%2Bunsubscribe@googlegroups.com) .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --
> 
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
> 
> ## --
> 
> Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> 
> * * *
> 
> You received this message because you are subscribed to a topic in the Google Groups "ODK Community" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/opendatakit/zwwIJ6oj0n0/unsubscribe](https://groups.google.com/d/topic/opendatakit/zwwIJ6oj0n0/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [June 5, 2015, 6:32pm UTC](https://forum.getodk.org/t/calculate-on-date-types/4345/8 "2015-06-05T18:32:00Z")

</div>

There is a lot of quirky behavior around dates, so be sure to test both the  
success and error conditions to ensure that your form logic is actually  
working.

> **···**
>
> On Fri, Jun 5, 2015 at 2:06 AM, Jan Priebe wrote:
> 
> > Thanks both!
> > 
> > Mitch, no worries- I really should have just tried that myself.
> > 
> > Colin, thanks for the tip, I didn’t realise I could use dates in math  
> > functions without having to convert them first – problem solved!
> > 
> > _From:_ [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com) [[mailto:opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)]  
> > \*On Behalf Of \*Mitch Sundt  
> > _Sent:_ 04 June 2015 22:45  
> > _To:_ ODK Community  
> > _Subject:_ Re: [ODK Community] Calculate on date types
> > 
> > Oops. My mistake.
> > 
> > The name of the function is:
> > 
> > decimal-date-time()
> > 
> > there is no decimal-date() function.
> > 
> > On Thu, Jun 4, 2015 at 10:41 AM, [colindmccann@gmail.com](mailto:colindmccann@gmail.com) wrote:
> > 
> > I was also unable to get decimal-date to work correctly.
> > 
> > However, I believe I have an approach that could work for your issue...  
> > you can perform basic math functions on date objects in ODK. That is, you  
> > can use div, -, etc (as well as \> and \<).
> > 
> > Snippet of my code:  
> > constraint = ( (((. - /data/ENROLDT) div 365.25) \>= 1)
> > 
> > So, extrapolating from that, you might try something like:  
> > ((${dateX} - ${dateY}) div 365.25) \> 1/4  
> > Or, more human readably  
> > ((${dateX} - ${dateY}) div 30) \> 3
> > 
> > On Thursday, June 4, 2015 at 1:13:46 PM UTC-4, [jan.p...@gmail.com](mailto:jan.p...@gmail.com) wrote:
> > 
> > > On Friday, May 15, 2015 at 5:58:27 PM UTC+1, Mitch Sundt wrote:
> > > 
> > > > There are various date-time functions available:  
> > > > [https://opendatakit.org/help/form-design/binding/](https://opendatakit.org/help/form-design/binding/)
> > > > 
> > > > e.g., decimal-date().
> > > > 
> > > > Note, however, that there are numerous bugs/issues with date-time  
> > > > arithmetic and getting the logic to respect and preserve the time portion  
> > > > of the date-time.
> > > > 
> > > > Carefully test to ensure that what you write actually works.
> > > > 
> > > > Hi,
> > > 
> > > I'm trying to write a simple formula to check whether occurs a date X  
> > > occurs at least 3 months after date Y, and if not, return a warning message.
> > > 
> > > To do this I have created a note that only shows when this condition is  
> > > not met.
> > > 
> > > I have tried this using an XLSForm that is then uploaded to KoboToolbox
> > > 
> > > Relevant field: decimal-date(${dateX}) - decimal-date(${dateY}) \> '90'
> > > 
> > > I have also tried putting the constraint directly in the XML file to  
> > > upload to ODK aggregate:
> > > 
> > > " decimal-date(dateX) - decimal-date(dateY) \> '90'"
> > > 
> > > in both cases I receive the error: " XPath evaluation: cannot handle  
> > > function 'decimal-date' "
> > > 
> > > This sounds like decimal-date isn't accepted at all as a function,  
> > > though the previous post suggest it is/should be.
> > > 
> > > Would appreciate any thoughts on this
> > > 
> > > Thanks
> > > 
> > > Jan
> > > 
> > > > On Fri, May 15, 2015 at 7:17 AM, [colind...@gmail.com](mailto:colind...@gmail.com) wrote:  
> > > > Hi all,
> > > > 
> > > > I'd like to display a field to the user:
> > > > 
> > > > Clinic information within 12 months of clinic enrolment (between  
> > > > and XXX)
> > > > 
> > > > I would the XXX to be ENRDT + 12 months.
> > > > 
> > > > I have tried using a calculate, eg
> > > > 
> > > > XXX =
> > > > 
> > > > but this is a bit of a shot in the dark (esp that + 12, heh).
> > > > 
> > > > There is probably also a cleaner way to do this (eg can I manipulate  
> > > > the content of an field?)
> > > > 
> > > > Suggestions are welcome, and thanks in advance,
> > > > 
> > > > Colin
> > > > 
> > > > --
> > > > 
> > > > --
> > > > 
> > > > Post: [opend...@googlegroups.com](mailto:opend...@googlegroups.com)
> > > > 
> > > > Unsubscribe: [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com)
> > > > 
> > > > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > > > 
> > > > * * *
> > > > 
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "ODK Community" group.
> > > > 
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [opendatakit...@googlegroups.com](mailto:opendatakit...@googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --
> > > > 
> > > > Mitch Sundt  
> > > > Software Engineer  
> > > > University of Washington  
> > > > [mitche...@gmail.com](mailto:mitche...@gmail.com)
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --
> > 
> > Mitch Sundt  
> > Software Engineer  
> > University of Washington  
> > [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "ODK Community" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/opendatakit/zwwIJ6oj0n0/unsubscribe](https://groups.google.com/d/topic/opendatakit/zwwIJ6oj0n0/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
