date_diff.asciidoc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [discrete]
  2. [[esql-date_diff]]
  3. === `DATE_DIFF`
  4. *Syntax*
  5. [.text-center]
  6. image::esql/functions/signature/date_diff.svg[Embedded,opts=inline]
  7. *Parameters*
  8. `unit`::
  9. Time difference unit.
  10. `startTimestamp`::
  11. Start timestamp.
  12. `endTimestamp`::
  13. End timestamp.
  14. *Description*
  15. Subtracts the `startTimestamp` from the `endTimestamp` and returns the
  16. difference in multiples of `unit`. If `startTimestamp` is later than the
  17. `endTimestamp`, negative values are returned.
  18. [cols="^,^",role="styled"]
  19. |===
  20. 2+h|Datetime difference units
  21. s|unit
  22. s|abbreviations
  23. | year | years, yy, yyyy
  24. | quarter | quarters, qq, q
  25. | month | months, mm, m
  26. | dayofyear | dy, y
  27. | day | days, dd, d
  28. | week | weeks, wk, ww
  29. | weekday | weekdays, dw
  30. | hour | hours, hh
  31. | minute | minutes, mi, n
  32. | second | seconds, ss, s
  33. | millisecond | milliseconds, ms
  34. | microsecond | microseconds, mcs
  35. | nanosecond | nanoseconds, ns
  36. |===
  37. *Supported types*
  38. include::types/date_diff.asciidoc[]
  39. *Example*
  40. [source.merge.styled,esql]
  41. ----
  42. include::{esql-specs}/date.csv-spec[tag=docsDateDiff]
  43. ----
  44. [%header.monospaced.styled,format=dsv,separator=|]
  45. |===
  46. include::{esql-specs}/date.csv-spec[tag=docsDateDiff-result]
  47. |===