Skip to main content

date_diff

The date function used to returns the difference between two date or datetime values as a given unit of duration. Takes three arguments, the start date, the end date, and the unit of duration (one of "year", "decade", "century", "quarter", "month", "week", "day", "hour", "minute", "second", or "millisecond").

Parameter

Type

dateValue1

datetime, date, time, datetimestamp, gyear, gyearmonth

dateValue2

datetime, date, time, datetimestamp, gyear, gyearmonth

units

string

Returns: integer

Example

Query:

PREFIX : <https://ddw-doccorp.linked.data.world/d/sparql-function-sample-queries/>
PREFIX fn: <http://data.world/function/functions#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT (fn:date_diff("2001-01-01"^^xsd:date, "2001-01-15"^^xsd:date, "day") as ?date_diff)
{
}

Run query

Results:

date_diff

14