date - 在 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 或替代选项马克逻辑
解决方案
您可以使用标准 XQuery持续时间算法直接计算:
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)
推荐阅读
- javascript - 用PHP爬取网站,但网站运行JS生成标记
- wordpress - 如何在索引循环上显示自定义字段值?
- batch-file - 用于重命名小于当前日期的所有文件的批处理脚本
- scala - Kafka Akka Streams Consumer 在超时后因 WakeupException 而中断。消息:空
- c# - RDLC 报告 - 无数据
- mysql - 为什么这条 SQL 语句不起作用
- c++ - 当一个变量用于多个函数范围时,我应该在私有类中声明一个变量吗?
- android - 不能在 onResponse 中使用适配器
- python - 多标签分类中的精度计算
- c++ - 使用 boost Spirit 解析成 STL 向量