Date and Time Functions
This topic describes the date, time, and duration functions in Anzo.
Typographical Conventions
This documentation uses the following conventions in function syntax:
CAPS
: Although SPARQL is case-insensitive, function names and other keywords are written in uppercase for readability.
[ argument ]
: Brackets are used to indicate optional arguments. Arguments without brackets are required.
Functions
- DATE: Returns an xsd:date value based on the specified year, month, and day.
- DATEPART: Returns the date part of a literal string, date, long, or dateTime value.
- DATETIME (or xsd:dateTime): Returns a dateTime value from the given string, long, or dateTime.
- DAY: Returns the day of the month from the specified date.
- DAYSFROMDURATION: Returns the days portion of a duration value.
- DUR_TO_MILLIS: Calculates the time in milliseconds from a duration or numeric value.
- DURATION: Returns an xsd:duration value from the given numeric or duration value.
- DURATIONFORMAT: Converts a duration or numeric value to a string in the specified duration format.
- DURATIONPERIODFORMAT: Calculates the duration between the given start and end values and returns a string in the specified duration format.
- FORMATDATE: Converts a numeric or date value into a string with the specified date format.
- HOUR: Returns the hour portion of the given dateTime value.
- MASKEDDATETIME: Replaces the year, month, day, hour, minute, second, and millisecond values for the given date or dateTime value with the new date and time values that you specify.
- MILLIS: Calculates the number of milliseconds in the given date or dateTime value.
- MINUTE: Returns the minutes portion of the given dateTime value.
- MONTH: Returns the month portion of the given dateTime value.
- NOW: Returns the current server date and time.
- NOWMILLIS: Returns the current server date and time in epoch milliseconds.
- PARSEDATETIME: Attempts to convert the given string or plain literal to a date, time, or dateTime value.
- SECOND: Returns the seconds portion of the given dateTime value.
- TIME: Returns an xsd:time value based on the specified hour, minute, and second values.
- TIMEPART: Returns the time part of a time or dateTime value.
- TIMEVALUE: Converts the specified RDF term type value to an xsd:time value.
- TIMEZONE: Returns as a duration the timezone part of a dateTime value.
- TODAY: Returns today's date based on the server date.
- TZ: Returns as a string the timezone from a dateTime value.
- WEEKDAY: Returns the day of the week from a date or dateTime value.
- WEEKNUM: Returns the week of the year in which the given date or dateTime occurs.
- xsd:date: Converts the specified string, date, or dateTime value to an xsd:date.
- YEAR: Returns the year portion of the given dateTime value.
- YEARMONTH: Returns the year and month (in the format "year-month") from the specified date or dateTime value.
DATE
This function returns an xsd:date value based on the specified year, month, and day values.
Syntax
DATE(year, month, day)
year
|
int |
An integer that represents the year. |
month
|
int |
An integer that represents the month. |
day
|
int |
An integer that represents the day. |
Returns
date |
The date according to the input values. |
DATEPART
This function returns the date part of a literal string, date, long, or dateTime value.
Syntax
DATEPART(value)
value
|
literal string, date, long, or dateTime |
The literal string, date, long, or dateTime value from which to return the date. |
Returns
date |
The date part of the input values. |
DATETIME (or xsd:dateTime)
This function returns a dateTime value from the given string, long, or dateTime.
Syntax
DATETIME(value)
value
|
string, long, dateTime |
The string, long, or dateTime value from which to return a dateTime. |
Returns
dateTime |
The dateTime value. |
DAY
This function returns the day of the month from the specified date value.
Syntax
DAY(value)
value
|
date |
The date value from which to return the day of the month. |
Returns
int |
The day of the month. |
DAYSFROMDURATION
This function returns the days portion of a duration value.
Syntax
DAYSFROMDURATION(value)
value
|
duration |
The duration value from which to return the days. |
Returns
long |
The number of days in the duration. |
DUR_TO_MILLIS
This function calculates the time in milliseconds from a duration or numeric value.
Syntax
DUR_TO_MILLIS(value)
value
|
duration, numeric |
The duration or numeric value from which to calculate the time in milliseconds. |
Returns
long |
The number of milliseconds. |
DURATION
This function returns an xsd:duration value from the given numeric or duration value.
Syntax
DURATION(value)
value
|
duration, numeric |
The duration or numeric value from which to return an xsd:duration. |
Returns
duration |
The duration value. |
DURATIONFORMAT
This function converts a duration or numeric value to a string in the specified duration format.
Syntax
DURATIONFORMAT(value [, format ])
value
|
duration, numeric |
The duration or numeric value to format. |
format
|
string |
An optional value that specifies the format to use for the resulting duration string. Anzo supports Pattern Tokens for defining the format:- y for year digits
- M for months
- d for days
- H for hours
- m for minutes
- s for seconds
- S for milliseconds
- 'text' for arbitrary text content
If format is not specified, H:mm:ss.SSS is used. |
Returns
string |
The duration as a string. |
DURATIONPERIODFORMAT
This function calculates the duration between the given start and end dateTime or numeric values and returns a string in the specified duration format.
Syntax
DURATIONPERIODFORMAT(start, end [, format ])
start
|
dateTime, numeric |
The dateTime or numeric value that is the start of the duration period. |
end
|
dateTime, numeric |
The dateTime or numeric value that is the end of the duration period. |
format
|
string |
An optional value that specifies the format to use for the resulting duration string. Anzo supports Pattern Tokens for defining the format:- y for year digits
- M for months
- d for days
- H for hours
- m for minutes
- s for seconds
- S for milliseconds
- 'text' for arbitrary text content
If format is not specified, the default is 'P'yyyy'Y'M'M'd'DT'H'H'm'M's.SSS'S' . The default value uses 'text' patterns with Pattern Tokens, which results in a string such as P1Y3M4DT1H4M44.000S . |
Returns
string |
The duration as a string. |
FORMATDATE
This function converts a numeric or date value into a string with the specified date format.
Syntax
FORMATDATE(value, format)
value
|
date, numeric |
The date or numeric value to convert to a string in the specified date format . |
format
|
string |
The format to use for the resulting date string. Anzo supports Pattern Tokens for defining the format:- y for year digits
- M for months
- d for days
- 'text' for arbitrary text content
For example, "yyyy.MM.dd" or "dd/MM/yyyy" . |
Returns
string |
The date as a string. |
HOUR
This function returns the hour portion of the given dateTime value.
Syntax
HOUR(value [, timezone ])
value
|
dateTime |
The dateTime value from which to return the hour portion. |
timezone
|
string |
An optional value that specifies the timezone for the value . |
Returns
MASKEDDATETIME
This function replaces the year, month, day, hour, minute, second, and millisecond values for the given date or dateTime value with the new date and time values that you specify.
Syntax
MASKEDDATETIME(value, year, month, day, hour, minute, second, milliseconds)
value
|
date, dateTime |
The date or dateTime for which to replace the year, month, date, hour, minute, second, and milliseconds values. |
year
|
int |
The year to include in the resulting dateTime value. |
month
|
int |
The month to include in the resulting dateTime value. |
day
|
int |
The day to include in the resulting dateTime value. |
hour
|
int |
The hour to include in the resulting dateTime value. |
minute
|
int |
The minutes value to include in the resulting dateTime value. |
second
|
int |
The seconds value to include in the resulting dateTime value. |
milliseconds
|
int |
The milliseconds value to include in the resulting dateTime value. |
Returns
dateTime |
The dateTime value with the specified input values. |
MILLIS
This function calculates the number of milliseconds in the given date or dateTime value.
Syntax
MILLIS(value)
value
|
date, dateTime |
The date or dateTime value for which to calculate the number of milliseconds. |
Returns
long |
The number of milliseconds. |
MINUTE
This function returns the minutes portion of the given dateTime value.
Syntax
MINUTE(value)
value
|
dateTime |
The dateTime value from which to return the minutes portion. |
Returns
int |
The minutes portion of the input value. |
MONTH
This function returns the month portion of the given dateTime value.
Syntax
MONTH(value)
value
|
dateTime |
The dateTime value from which to return the month portion. |
Returns
NOW
This function returns the current server date and time.
Syntax
NOW([ timezone ])
timezone
|
string |
An optional value that specifies the timezone for which to return the current dateTime. |
Returns
dateTime |
The current server date and time. |
NOWMILLIS
This function returns the current server date and time in epoch milliseconds.
Syntax
NOWMILLIS()
Returns
long |
The current server date and time in milliseconds. |
PARSEDATETIME
This function attempts to convert the given string or plain literal to a date, time, or dateTime value. For values that do not include a timezone, Anzo stores them in GMT. Values that include a timezone are stored as the appropriate value in GMT for that timezone.
Syntax
PARSEDATETIME(value [, output_type ] [, format ])
value
|
string, literal |
The string or plain literal value to convert to a date, time, or dateTime. |
output_type
|
URI |
An optional URI (xsd:date , xsd:time , or xsd:dateTime ) that specifies the type of value to return. If output_type is not specified, dateTime is returned. |
format
|
string |
An optional string that species the format to use for the resulting date, time, or dateTime value. Anzo supports Pattern Tokens for defining the format:- y for year digits
- M for months
- d for days
- H for hours
- m for minutes
- s for seconds
- S for milliseconds
- 'text' for arbitrary text content
For example, "yyyy.MM.dd HH:mm" or "dd/MM/yyyy HH:mm:ss" . |
Returns
date, time, or dateTime |
The conversion of the string to the desired type. |
SECOND
This function returns the seconds portion of the given dateTime value.
Syntax
SECOND(value)
value
|
dateTime |
The dateTime value from which to return the seconds portion. |
Returns
int |
The seconds portion of the input value. |
TIME
This function returns an xsd:time value based on the specified hour, minute, and second values.
Syntax
TIME(hour, minute, second)
hour
|
int |
An integer that represents the hour. |
minute
|
int |
An integer that represents the minute. |
second
|
int |
An integer that represents the seconds. |
Returns
time |
The time according to the input values. |
TIMEPART
This function returns the time part of a time or dateTime value.
Syntax
TIMEPART(value)
value
|
time, dateTime |
The time or dateTime value from which to return the time portion. |
Returns
time |
The time portion of the input value. |
TIMEVALUE
This function converts the specified RDF term type value to an xsd:time value.
Syntax
TIMEVALUE(value)
value
|
RDF term |
The literal, URI, or blank node value to convert to a time value. |
Returns
time |
The conversion of the term to a time value. |
TIMEZONE
This function returns the timezone part of a dateTime value as a duration. An error is returned if the input value does not include the timezone.
Syntax
TIMEZONE(value)
value
|
dateTime |
The dateTime value to return the timezone from. |
Returns
duration |
The timezone in duration format. |
TODAY
This function returns today's date based on the server date.
Syntax
TODAY()
Returns
date |
Today's date according to the server. |
TZ
This function returns the timezone part of a dateTime value as a string.
Syntax
TZ(value)
value
|
dateTime |
The dateTime value to return the timezone from. |
Returns
string |
The timezone as a string. |
WEEKDAY
This function returns the day of the week from a date or dateTime value.
Syntax
WEEKDAY(value [, day_number_start ])
value
|
date, dateTime |
The date or dateTime value from which to return the day of the week. |
day_number_start
|
int |
An optional value of 1, 2, or 3 that defines how the days of the week are represented as numbers.- 1 means Sunday is day 1. Saturday is day 7.
- 2 means Monday is day 1. Sunday is day 7.
- 3 means Monday is day 0. Sunday is day 6.
If day_number_start is not specified, the default value is 1. |
Returns
int |
The day of the week from the input values. |
WEEKNUM
This function returns the week of the year in which the given date or dateTime occurs.
Syntax
WEEKNUM(value [, day_week_begins ])
value
|
date, dateTime |
The date or dateTime value from which to return the week number. |
day_week_begins
|
int |
An optional value of 1 or 2 that defines which day the weeks start on.- 1 means a new week starts on Sunday.
- 2 means a new week starts on Monday.
If day_week_begins is not specified, the default value is 1. |
Returns
int |
The week of the year the input value falls in. |
xsd:date
This function converts the specified string, date, or dateTime value to an xsd:date.
Syntax
xsd:date(value)
value
|
string, date, dateTime |
The string, date, or dateTime value to convert to an xsd:date. |
Returns
date |
The input values converted to dates. |
YEAR
This function returns the year portion of the given dateTime value.
Syntax
YEAR(value)
value
|
dateTime |
The dateTime value to return the year from. |
Returns
int |
The year portion of the input values. |
YEARMONTH
This function returns the year and month (in the format "year-month") from the specified date or dateTime value.
Syntax
YEARMONTH(value)
value
|
literal date or dateTime |
The value to return the year-month from. |
Returns
gYearMonth |
The year-month from the input values. |