MarkLogic 9 Product Documentation
sql:datediff

sql:datediff(
   $datepart as xs:string,
   $startdate as item(),
   $enddate as item()
) as xs:integer?

Summary

Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.

Parameters
datepart Is the part of startdate and enddate that specifies the type of boundary crossed. The following table lists all valid datepart arguments. User-defined variable equivalents are not valid.

Options:

datepart parameter abbreviation includes:

"year","yyyy","yy"
The year part of the date
"quarter","qq","q"
The quarter part of the date
"month","mm","m"
The month part of the date
"dayofyear","dy","y"
The day of the year from the date
"day","dd","d"
The day of the month from the date
"week","wk","ww"
The week of the year from the date
"weekday","dw"
The day of the week from the date
"hour","hh"
The hour of the day from the date
"minute","mi","n"
The minute of the hour from the date
"second","ss","s"
The second of the minute from the date
"millisecond","ms"
The millisecond of the minute from the date
"microsecond","msc"
The microsecond of the minute from the date
"nanosecond","ns"
The nanosecond of the minute from the date
startdate Is an expression that can be resolved to a time, date, datetime or value. date can be an expression, column expression, user-defined variable or string literal. startdate is subtracted from enddate.
enddate Same as startdate.

Usage Notes

This function is only available for use within SQL; it is not available directly from XQuery, XSLT, or JavaScript.

Example

select datediff('day','2008-06-05','2008-08-05')
returns -61

Example

sql:datediff('day','2008-08-05','2008-06-05')
returns 61
Powered by MarkLogic Server | Terms of Use | Privacy Policy