mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-29 18:03:32 -04:00
* Functions starting with A * Functions starting with 'C' * More 'C' functions * Fix tests * Fix missing snippet * DATE_* functions * Apply suggestions from code review Co-authored-by: Bogdan Pintea <pintea@mailbox.org> --------- Co-authored-by: Bogdan Pintea <pintea@mailbox.org>
57 lines
1.2 KiB
Text
57 lines
1.2 KiB
Text
[discrete]
|
|
[[esql-date_trunc]]
|
|
=== `DATE_TRUNC`
|
|
|
|
*Syntax*
|
|
|
|
[source,esql]
|
|
----
|
|
DATE_TRUNC(interval, date)
|
|
----
|
|
|
|
*Parameters*
|
|
|
|
`interval`::
|
|
Interval, expressed using the <<esql-timespan-literals,timespan literal
|
|
syntax>>. If `null`, the function returns `null`.
|
|
|
|
`date`::
|
|
Date expression. If `null`, the function returns `null`.
|
|
|
|
*Description*
|
|
|
|
Rounds down a date to the closest interval.
|
|
|
|
*Examples*
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/date.csv-spec[tag=docsDateTrunc]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/date.csv-spec[tag=docsDateTrunc-result]
|
|
|===
|
|
|
|
Combine `DATE_TRUNC` with <<esql-stats-by>> to create date histograms. For
|
|
example, the number of hires per year:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/date.csv-spec[tag=docsDateTruncHistogram]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/date.csv-spec[tag=docsDateTruncHistogram-result]
|
|
|===
|
|
|
|
Or an hourly error rate:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/conditional.csv-spec[tag=docsCaseHourlyErrorRate]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/conditional.csv-spec[tag=docsCaseHourlyErrorRate-result]
|
|
|===
|