date_diff.asciidoc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. include::types/date_diff.asciidoc[]
  38. *Example*
  39. [source.merge.styled,esql]
  40. ----
  41. include::{esql-specs}/date.csv-spec[tag=docsDateDiff]
  42. ----
  43. [%header.monospaced.styled,format=dsv,separator=|]
  44. |===
  45. include::{esql-specs}/date.csv-spec[tag=docsDateDiff-result]
  46. |===