Larissa Carvalho
Larissa Carvalho

Reputation: 11

Remove hours from DateTime XQuery

So, I have this expression in XML:

<can:interactionDate>2020-06-24T12:42:55</can:interactionDate>

And this is the actual xquery:

<ser:documentIssuanceDate>{ data($body/.../can:interactionDate) }</ser:documentIssuanceDate>

As you can see, it doesnt make any transformations in the field.

I need to send only the date, without the hours.

I'm expecting a result like this:

<ser:documentIssuanceDate>2020-06-24</ser:documentIssuanceDate>

Is there any methods to do such thing?

Upvotes: 0

Views: 321

Answers (2)

Leo W&#246;rteler
Leo W&#246;rteler

Reputation: 4241

The "proper" way to do this is using the date and time processing functions of XQuery. In your case it is sufficient to parse the string as an xs:dateTime and then cast it to an xs:date, thereby discarding the time component:

<ser:documentIssuanceDate>{ xs:date(xs:dateTime($doc/.../can:interactionDate)) }</ser:documentIssuanceDate>

This returns <ser:documentIssuanceDate>2020-06-24</ser:documentIssuanceDate> as expected.

Upvotes: 3

Jack Fleeting
Jack Fleeting

Reputation: 24930

Try changing this part

$body/.../can:interactionDate

to

$body/.../can:interactionDate/substring-before(.,"T")

and see if that works.

Upvotes: 2

Related Questions