date_extract.asciidoc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. [discrete]
  2. [[esql-date_extract]]
  3. === `DATE_EXTRACT`
  4. *Syntax*
  5. [source,esql]
  6. ----
  7. DATE_EXTRACT(date_part, date)
  8. ----
  9. *Parameters*
  10. `date_part`::
  11. Part of the date to extract. Can be: `aligned_day_of_week_in_month`,
  12. `aligned_day_of_week_in_year`, `aligned_week_of_month`, `aligned_week_of_year`,
  13. `ampm_of_day`, `clock_hour_of_ampm`, `clock_hour_of_day`, `day_of_month`,
  14. `day_of_week`, `day_of_year`, `epoch_day`, `era`, `hour_of_ampm`, `hour_of_day`,
  15. `instant_seconds`, `micro_of_day`, `micro_of_second`, `milli_of_day`,
  16. `milli_of_second`, `minute_of_day`, `minute_of_hour`, `month_of_year`,
  17. `nano_of_day`, `nano_of_second`, `offset_seconds`, `proleptic_month`,
  18. `second_of_day`, `second_of_minute`, `year`, or `year_of_era`. Refer to
  19. https://docs.oracle.com/javase/8/docs/api/java/time/temporal/ChronoField.html[java.time.temporal.ChronoField]
  20. for a description of these values.
  21. +
  22. If `null`, the function returns `null`.
  23. `date`::
  24. Date expression. If `null`, the function returns `null`.
  25. *Description*
  26. Extracts parts of a date, like year, month, day, hour.
  27. *Examples*
  28. [source.merge.styled,esql]
  29. ----
  30. include::{esql-specs}/date.csv-spec[tag=dateExtract]
  31. ----
  32. [%header.monospaced.styled,format=dsv,separator=|]
  33. |===
  34. include::{esql-specs}/date.csv-spec[tag=dateExtract-result]
  35. |===
  36. Find all events that occurred outside of business hours (before 9 AM or after 5
  37. PM), on any given date:
  38. [source.merge.styled,esql]
  39. ----
  40. include::{esql-specs}/date.csv-spec[tag=docsDateExtractBusinessHours]
  41. ----
  42. [%header.monospaced.styled,format=dsv,separator=|]
  43. |===
  44. include::{esql-specs}/date.csv-spec[tag=docsDateExtractBusinessHours-result]
  45. |===