Loading TOC...

MarkLogic 10 Product Documentation
sql:dateadd

sql:dateadd(
   $datepart as xs:string,
   $number as xs:integer,
   $date as item()
) as item()

Summary

Returns a specified date with the specified number interval (signed integer) added to a specified datepart of that date

Parameters
datepart Is the part of date where the number will be added. The following table lists all valid datepart arguments. User-defined variable equivalents are not valid. The return data type is the data type of the date argument.

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
number This number will be added to the datepart of the given date.
date Is an expression that can be resolved to a time, date or datetime, value. date can be an expression, column expression, user-defined variable or string literal. startdate is subtracted from enddate.

Usage Notes

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

Example

 sql:dateadd('day',45, '2008-11-11T13:23:44.657')
returns   2008-12-26T13:23:44.657

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.