Skip to main content

date_trunc

The date function used to truncate a date or datetime value to the start of a given unit of duration. Takes two arguments, the date to truncate and the unit of duration (one of "year", "decade", "century", "quarter", "month", "week", "day", "hour", "minute", "second", or "millisecond"). The function returns a value of the same type as it's first argument.

Returns: any

Table 1.

Parameter

Type

dateValue

datetime, date, time, datetimestamp, gyear, gyearmonth

units

string



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_trunc("2001-03-15"^^xsd:date, "month") as ?date_diff)
{
}

Try the query

Table 2. Results

date_diff

2001-03-01