计算XQuery中dateTime值之间的分钟差异

时间:2018-01-19 11:40:06

标签: xquery marklogic

我想计算日期时间(以分钟为单位)之间的差异

val

我尝试使用

xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]","2017-01-17T08:00:00")
xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]","2017-01-17T22:45:00")

输出

xquery version "0.9-ml"
fn:subtract-dateTimes-yielding-dayTimeDuration(
  xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]","2017-01-17T08:00:00"),
  xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]","2017-01-17T22:45:00")
)

我想用分钟输出

2 个答案:

答案 0 :(得分:4)

提取日期,并除以dayTimeDuration 1分钟:

let $date1 := xs:dateTime("2017-01-17T08:00:00")
let $date2 := xs:dateTime("2017-01-17T22:45:00")
return fn:abs(($date1 - $date2) div xs:dayTimeDuration("PT1M"))

HTH!

答案 1 :(得分:4)

您还可以使用functx库functx:total-minutes-from-duration()

xquery version "1.0-ml";
import module namespace functx = "http://www.functx.com" at
 "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";

functx:total-minutes-from-duration(
  xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]","2017-01-17T08:00:00")
  - xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]","2017-01-17T22:45:00")
)