date - 获取 Marklogic 中选定日期的第一天和最后一天日期

标签 date xquery marklogic marklogic-8

我正在尝试使用 MarkLogic 获取任何选定日期的第一天和最后一天日期。
示例:

let $date := xs:date("2018-08-24")      
let $firstDay := "*Should be 1st day of month - of $date*"  
let $lastDay := "*Should be last day of month - of $date*"  
return ("$firstDay:",$firstDay,"$lastDay:",$lastDay)

预计输出日期:

  • $firstDay:2018-08-01
  • $lastDay:2018-08-31

我可以使用 functx:first-day-of-month($date) 来获取此日期 functx:last-day-of-month($date) 但我想知道 MarkLogic 是否提供任何 API 或替代选项

最佳答案

您可以使用标准 XQuery 直接计算此值 duration arithmetic :

let $date := xs:date("2018-08-24")

let $one-day := xs:dayTimeDuration('P1D')
let $one-month := xs:yearMonthDuration('P1M')
(: subtract days to get to the 1st of the month :)
let $firstDay := $date - (fn:day-from-date($date) - 1) * $one-day
(: get the 1st of the next month and then subtract one day :)
let $lastDay  := $firstDay + $one-month - $one-day

return ("$firstDay:",$firstDay,"$lastDay:",$lastDay)

关于date - 获取 Marklogic 中选定日期的第一天和最后一天日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52148198/

相关文章:

marklogic - if() 以一种奇怪的方式处理 bool 值

javascript - 对象节点到元素节点的转换失败?

c# - 在处理 C# Outlook 之前按接收时间对电子邮件进行排序

javascript - 获取 2014 年特定月份的正确天数 javascript

java - Java java.util.Calendar 中语言环境设置的目的是什么?

types - XQuery:为什么 "() = ()"和 "() eq ()"都计算为 false?

r - ddply,按日期排列

xml - 全文 Xquery (Lucene/KWIC) 对 "tagged"结果不起作用。 eXist-db 错误?

sql-server - T-SQL 2014 XQuery 使用子字符串的解决方案

email - 无法使用marklogic的xdmp发送电子邮件:email function