marklogicmarklogic-dhf

How to do arithmetic operation in TDE


I have requirement to get previous date of one of the date field, for that I am doing below operation in TDE. But I am getting error on this operation. How can I achieve this

<tde:column>
<tde:name>PreStartDate</tde:name>
<tde:scalar-type>date</tde:scalar-type>
<tde:val>(hdm:StartDate - xs:dayTimeDuration("P1D"))</tde:val>
<tde:nullable>true</tde:nullable>
</tde:column>

Solution

  • I see your comment stating that hdm:StartDate is already in Date format. As written, however, what you have is a string that looks like a Date (well, more precisely an untypedAtomic). It needs to be converted to an actual date type before you can subtract a dayTimeDuration from it.

    <tde:column>
      <tde:name>PreStartDate</tde:name>
      <tde:scalar-type>date</tde:scalar-type>
      <tde:val>(xs:date(hdm:StartDate) - xs:dayTimeDuration("P1D"))</tde:val>
      <tde:nullable>true</tde:nullable>
    </tde:column>