Loading TOC...

MarkLogic 12 EA 2 Product Documentation
sql:datepart

sql:datepart(
   $datepart as xs:string?,
   $date as xs:genericDateTimeArg
) as xs:integer?

Summary

Returns an integer that represents the specified datepart of the specified date.

If datepart or date is the empty sequence, the function returns the empty sequence.

Parameters
datepart The part of date that to be returned.

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
"TZoffset","tz"
The timezone offset from the date
date Is an expression that can be resolved to a xs:date, xs:time, xs:dateTime. date can be an expression, column expression,user-defined variable, or string literal.

Usage Notes

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

Example

select datepart('yy','2007-10-30T12:15:32.1234567+05:10')
returns 2007

Example

sql:datepart("dayofyear",'2007-10-30T12:15:32.1234567+05:10')
returns 303

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