xquerymarklogicctsmarklogic-8

Format date time in cts:element-values


I want to format dateTime with in the cts:element-values itself. Can anyone help me around this?

I have a dateTime format string -

let $date-format := "[Y0001]-[M01]-[D01]T[h01]:[m01]:[s01].[f1]"

and I want to use it in a query like this -

cts:element-values(
  xs:QName($field),
  (), 
  ($direction), 
  cts:and-query((cts:collection-query("urn:iddn:collections:searchable"), cts:query($cts-query)))
  )

Provided $field is of type dateTime.


Solution

  • You can accomplish this by writing a User-Defined Function. UDFs are run as map/reduce, so they are very fast even with a large data set. I wrote an example UDF to create a day-of-the-week facet based on dateTime data. That example is based on MarkLogic 6, but should still work in MarkLogic 8.

    The good thing is that UDFs are very fast. The tricky part is that you'll have to write it in C++. Full documentation in the User-Defined Functions section of the MarkLogic documentation.