在 Marklogic 中获取所选日期月份的第一天和最后一天日期
Get first day and last day dates of month of selected date in Marklogic
我正在尝试使用 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) 但我想知道是否有任何 API 或 MarkLogic[=27 提供的替代选项=]
您可以使用标准 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)
我正在尝试使用 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) 但我想知道是否有任何 API 或 MarkLogic[=27 提供的替代选项=]
您可以使用标准 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)