1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039 |
- [role="xpack"]
- [testenv="basic"]
- [[sql-functions-datetime]]
- === Date/Time and Interval Functions and Operators
- {es-sql} offers a wide range of facilities for performing date/time manipulations.
- [[sql-functions-datetime-interval]]
- ==== Intervals
- A common requirement when dealing with date/time in general revolves around
- the notion of `interval`, a topic that is worth exploring in the context of {es} and {es-sql}.
- {es} has comprehensive support for <<date-math, date math>> both inside <<date-math-index-names, index names>> and <<mapping-date-format, queries>>.
- Inside {es-sql} the former is supported as is by passing the expression in the table name, while the latter is supported through the standard SQL `INTERVAL`.
- The table below shows the mapping between {es} and {es-sql}:
- [cols="^m,^m"]
- |==========================
- s|{es}
- s|{es-sql}
- 2+h| Index/Table datetime math
- 2+|<index-{now/M{YYYY.MM}}>
- 2+h| Query date/time math
- | 1y | INTERVAL 1 YEAR
- | 2M | INTERVAL 2 MONTH
- | 3w | INTERVAL 21 DAY
- | 4d | INTERVAL 4 DAY
- | 5h | INTERVAL 5 HOUR
- | 6m | INTERVAL 6 MINUTE
- | 7s | INTERVAL 7 SECOND
- |==========================
- `INTERVAL` allows either `YEAR` and `MONTH` to be mixed together _or_ `DAY`, `HOUR`, `MINUTE` and `SECOND`.
- TIP: {es-sql} accepts also the plural for each time unit (e.g. both `YEAR` and `YEARS` are valid).
- Example of the possible combinations below:
- [cols="^,^"]
- |===
- s|Interval
- s|Description
- | `INTERVAL '1-2' YEAR TO MONTH` | 1 year and 2 months
- | `INTERVAL '3 4' DAYS TO HOURS` | 3 days and 4 hours
- | `INTERVAL '5 6:12' DAYS TO MINUTES` | 5 days, 6 hours and 12 minutes
- | `INTERVAL '3 4:56:01' DAY TO SECOND` | 3 days, 4 hours, 56 minutes and 1 second
- | `INTERVAL '2 3:45:01.23456789' DAY TO SECOND` | 2 days, 3 hours, 45 minutes, 1 second and 234567890 nanoseconds
- | `INTERVAL '123:45' HOUR TO MINUTES` | 123 hours and 45 minutes
- | `INTERVAL '65:43:21.0123' HOUR TO SECONDS` | 65 hours, 43 minutes, 21 seconds and 12300000 nanoseconds
- | `INTERVAL '45:01.23' MINUTES TO SECONDS` | 45 minutes, 1 second and 230000000 nanoseconds
- |===
- ==== Operators
- Basic arithmetic operators (`+`, `-`, `*`) support date/time parameters as indicated below:
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dtIntervalPlusInterval]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dtDateTimePlusInterval]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dtMinusInterval]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dtIntervalMinusInterval]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dtDateTimeMinusInterval]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dtIntervalMul]
- --------------------------------------------------
- ==== Functions
- Functions that target date/time.
- [[sql-functions-current-date]]
- ==== `CURRENT_DATE/CURDATE`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- CURRENT_DATE
- CURRENT_DATE()
- CURDATE()
- --------------------------------------------------
- *Input*: _none_
- *Output*: date
- .Description:
- Returns the date (no time part) when the current query reached the server.
- It can be used both as a keyword: `CURRENT_DATE` or as a function with no arguments: `CURRENT_DATE()`.
- [NOTE]
- Unlike CURRENT_DATE, `CURDATE()` can only be used as a function with no arguments and not as a keyword.
- This method always returns the same value for its every occurrence within the same query.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[currentDate]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[currentDateFunction]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[curDateFunction]
- --------------------------------------------------
- Typically, this function (as well as its twin <<sql-functions-today,TODAY())>> function
- is used for relative date filtering:
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[filterToday]
- --------------------------------------------------
- [[sql-functions-current-time]]
- ==== `CURRENT_TIME/CURTIME`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- CURRENT_TIME
- CURRENT_TIME([precision]) <1>
- CURTIME
- --------------------------------------------------
- *Input*:
- <1> fractional digits; optional
- *Output*: time
- .Description:
- Returns the time when the current query reached the server.
- As a function, `CURRENT_TIME()` accepts _precision_ as an optional
- parameter for rounding the second fractional digits (nanoseconds). The default _precision_ is 3,
- meaning a milliseconds precision current time will be returned.
- This method always returns the same value for its every occurrence within the same query.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[currentTime]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[currentTimeFunction]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[curTimeFunction]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[currentTimeFunctionPrecision]
- --------------------------------------------------
- Typically, this function is used for relative date/time filtering:
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[filterCurrentTime]
- --------------------------------------------------
- [IMPORTANT]
- Currently, using a _precision_ greater than 3 doesn't make any difference to the output of the
- function as the maximum number of second fractional digits returned is 3 (milliseconds).
- [[sql-functions-current-timestamp]]
- ==== `CURRENT_TIMESTAMP`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- CURRENT_TIMESTAMP
- CURRENT_TIMESTAMP([precision]) <1>
- --------------------------------------------------
- *Input*:
- <1> fractional digits; optional
- *Output*: date/time
- .Description:
- Returns the date/time when the current query reached the server.
- As a function, `CURRENT_TIMESTAMP()` accepts _precision_ as an optional
- parameter for rounding the second fractional digits (nanoseconds). The default _precision_ is 3,
- meaning a milliseconds precision current date/time will be returned.
- This method always returns the same value for its every occurrence within the same query.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[curTs]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[curTsFunction]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[curTsFunctionPrecision]
- --------------------------------------------------
- Typically, this function (as well as its twin <<sql-functions-now,NOW())>> function is used for
- relative date/time filtering:
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[filterNow]
- --------------------------------------------------
- [IMPORTANT]
- Currently, using a _precision_ greater than 3 doesn't make any difference to the output of the
- function as the maximum number of second fractional digits returned is 3 (milliseconds).
- [[sql-functions-datetime-add]]
- ==== `DATE_ADD/DATEADD/TIMESTAMP_ADD/TIMESTAMPADD`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DATE_ADD(
- string_exp, <1>
- integer_exp, <2>
- datetime_exp) <3>
- --------------------------------------------------
- *Input*:
- <1> string expression denoting the date/time unit to add to the date/datetime
- <2> integer expression denoting how many times the above unit should be added to/from the date/datetime,
- if a negative value is used it results to a subtraction from the date/datetime
- <3> date/datetime expression
- *Output*: datetime
- .Description:
- Add the given number of date/time units to a date/datetime. If the number of units is negative then it's subtracted from
- the date/datetime. If any of the three arguments is `null` a `null` is returned.
- [WARNING]
- If the second argument is a long there is possibility of truncation since an integer value will be extracted and
- used from that long.
- [cols="^,^"]
- |===
- 2+h|Datetime units to add/subtract
- s|unit
- s|abbreviations
- | year | years, yy, yyyy
- | quarter | quarters, qq, q
- | month | months, mm, m
- | dayofyear | dy, y
- | day | days, dd, d
- | week | weeks, wk, ww
- | weekday | weekdays, dw
- | hour | hours, hh
- | minute | minutes, mi, n
- | second | seconds, ss, s
- | millisecond | milliseconds, ms
- | microsecond | microseconds, mcs
- | nanosecond | nanoseconds, ns
- |===
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateAddDateTimeYears]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateAddDateTimeWeeks]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateAddDateTimeSeconds]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateAddDateQuarters]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateAddDateMinutes]
- --------------------------------------------------
- [[sql-functions-datetime-diff]]
- ==== `DATE_DIFF/DATEDIFF/TIMESTAMP_DIFF/TIMESTAMPDIFF`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DATE_DIFF(
- string_exp, <1>
- datetime_exp, <2>
- datetime_exp) <3>
- --------------------------------------------------
- *Input*:
- <1> string expression denoting the date/time unit difference between the following two date/datetime expressions
- <2> start date/datetime expression
- <3> end date/datetime expression
- *Output*: integer
- .Description:
- Subtract the second argument from the third argument and return their difference in multiples of the unit
- specified in the first argument. If the second argument (start) is greater than the third argument (end),
- then negative values are returned. If any of the three arguments is `null`, a `null` is returned.
- [cols="^,^"]
- |===
- 2+h|Datetime difference units
- s|unit
- s|abbreviations
- | year | years, yy, yyyy
- | quarter | quarters, qq, q
- | month | months, mm, m
- | dayofyear | dy, y
- | day | days, dd, d
- | week | weeks, wk, ww
- | weekday | weekdays, dw
- | hour | hours, hh
- | minute | minutes, mi, n
- | second | seconds, ss, s
- | millisecond | milliseconds, ms
- | microsecond | microseconds, mcs
- | nanosecond | nanoseconds, ns
- |===
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeYears]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeWeeks]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeSeconds]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateQuarters]
- --------------------------------------------------
- [NOTE]
- For `hour` and `minute`, `DATEDIFF` doesn't do any rounding, but instead first truncates
- the more detailed time fields on the 2 dates to zero and then calculates the subtraction.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeHours]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateTimeMinutes]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dateDiffDateMinutes]
- --------------------------------------------------
- [[sql-functions-datetime-part]]
- ==== `DATE_PART/DATEPART`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DATE_PART(
- string_exp, <1>
- datetime_exp) <2>
- --------------------------------------------------
- *Input*:
- <1> string expression denoting the unit to extract from the date/datetime
- <2> date/datetime expression
- *Output*: integer
- .Description:
- Extract the specified unit from a date/datetime. If any of the two arguments is `null` a `null` is returned.
- It's similar to <<sql-functions-datetime-extract>> but with different names and aliases for the units and
- provides more options (e.g.: `TZOFFSET`).
- [cols="^,^"]
- |===
- 2+h|Datetime units to extract
- s|unit
- s|abbreviations
- | year | years, yy, yyyy
- | quarter | quarters, qq, q
- | month | months, mm, m
- | dayofyear | dy, y
- | day | days, dd, d
- | week | weeks, wk, ww
- | weekday | weekdays, dw
- | hour | hours, hh
- | minute | minutes, mi, n
- | second | seconds, ss, s
- | millisecond | milliseconds, ms
- | microsecond | microseconds, mcs
- | nanosecond | nanoseconds, ns
- | tzoffset | tz
- |===
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateTimeYears]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateTimeMinutes]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateQuarter]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateMonth]
- --------------------------------------------------
- [NOTE]
- For `week` and `weekday` the unit is extracted using the non-ISO calculation, which means
- that a given week is considered to start from Sunday, not Monday.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateTimeWeek]
- --------------------------------------------------
- [NOTE]
- The `tzoffset` returns the total number of minutes (signed) that represent the time zone's offset.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateTimeTzOffsetPlus]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[datePartDateTimeTzOffsetMinus]
- --------------------------------------------------
- [[sql-functions-datetime-trunc]]
- ==== `DATE_TRUNC/DATETRUNC`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DATE_TRUNC(
- string_exp, <1>
- datetime_exp) <2>
- --------------------------------------------------
- *Input*:
- <1> string expression denoting the unit to which the date/datetime should be truncated to
- <2> date/datetime expression
- *Output*: datetime
- .Description:
- Truncate the date/datetime to the specified unit by setting all fields that are less significant than the specified
- one to zero (or one, for day, day of week and month). If any of the two arguments is `null` a `null` is returned.
- [cols="^,^"]
- |===
- 2+h|Datetime truncation units
- s|unit
- s|abbreviations
- | millennium | millennia
- | century | centuries
- | decade | decades
- | year | years, yy, yyyy
- | quarter | quarters, qq, q
- | month | months, mm, m
- | week | weeks, wk, ww
- | day | days, dd, d
- | hour | hours, hh
- | minute | minutes, mi, n
- | second | seconds, ss, s
- | millisecond | milliseconds, ms
- | microsecond | microseconds, mcs
- | nanosecond | nanoseconds, ns
- |===
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[truncateDateTimeMillennium]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[truncateDateTimeWeek]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[truncateDateTimeMinutes]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[truncateDateDecades]
- --------------------------------------------------
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[truncateDateQuarter]
- --------------------------------------------------
- [[sql-functions-datetime-day]]
- ==== `DAY_OF_MONTH/DOM/DAY`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DAY_OF_MONTH(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the day of the month from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dayOfMonth]
- --------------------------------------------------
- [[sql-functions-datetime-dow]]
- ==== `DAY_OF_WEEK/DAYOFWEEK/DOW`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DAY_OF_WEEK(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the day of the week from a date/datetime. Sunday is `1`, Monday is `2`, etc.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dayOfWeek]
- --------------------------------------------------
- [[sql-functions-datetime-doy]]
- ==== `DAY_OF_YEAR/DOY`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DAY_OF_YEAR(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the day of the year from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dayOfYear]
- --------------------------------------------------
- [[sql-functions-datetime-dayname]]
- ==== `DAY_NAME/DAYNAME`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- DAY_NAME(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: string
- .Description:
- Extract the day of the week from a date/datetime in text format (`Monday`, `Tuesday`...).
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dayName]
- --------------------------------------------------
- [[sql-functions-datetime-hour]]
- ==== `HOUR_OF_DAY/HOUR`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- HOUR_OF_DAY(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the hour of the day from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[hourOfDay]
- --------------------------------------------------
- [[sql-functions-datetime-isodow]]
- ==== `ISO_DAY_OF_WEEK/ISODAYOFWEEK/ISODOW/IDOW`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- ISO_DAY_OF_WEEK(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the day of the week from a date/datetime, following the https://en.wikipedia.org/wiki/ISO_week_date[ISO 8601 standard].
- Monday is `1`, Tuesday is `2`, etc.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[isoDayOfWeek]
- --------------------------------------------------
- [[sql-functions-datetime-isoweek]]
- ==== `ISO_WEEK_OF_YEAR/ISOWEEKOFYEAR/ISOWEEK/IWOY/IW`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- ISO_WEEK_OF_YEAR(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the week of the year from a date/datetime, following https://en.wikipedia.org/wiki/ISO_week_date[ISO 8601 standard]. The first week
- of a year is the first week with a majority (4 or more) of its days in January.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[isoWeekOfYear]
- --------------------------------------------------
- [[sql-functions-datetime-minuteofday]]
- ==== `MINUTE_OF_DAY`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- MINUTE_OF_DAY(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the minute of the day from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[minuteOfDay]
- --------------------------------------------------
- [[sql-functions-datetime-minute]]
- ==== `MINUTE_OF_HOUR/MINUTE`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- MINUTE_OF_HOUR(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the minute of the hour from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[minuteOfHour]
- --------------------------------------------------
- [[sql-functions-datetime-month]]
- ==== `MONTH_OF_YEAR/MONTH`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- MONTH(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the month of the year from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[monthOfYear]
- --------------------------------------------------
- [[sql-functions-datetime-monthname]]
- ==== `MONTH_NAME/MONTHNAME`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- MONTH_NAME(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: string
- .Description:
- Extract the month from a date/datetime in text format (`January`, `February`...).
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[monthName]
- --------------------------------------------------
- [[sql-functions-now]]
- ==== `NOW`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- NOW()
- --------------------------------------------------
- *Input*: _none_
- *Output*: datetime
- .Description:
- This function offers the same functionality as <<sql-functions-current-timestamp,CURRENT_TIMESTAMP()>> function: returns
- the datetime when the current query reached the server. This method always returns the same value for its every
- occurrence within the same query.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[nowFunction]
- --------------------------------------------------
- Typically, this function (as well as its twin <<sql-functions-current-timestamp,CURRENT_TIMESTAMP())>> function is used
- for relative date/time filtering:
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[filterNow]
- --------------------------------------------------
- [[sql-functions-datetime-second]]
- ==== `SECOND_OF_MINUTE/SECOND`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- SECOND_OF_MINUTE(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the second of the minute from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[secondOfMinute]
- --------------------------------------------------
- [[sql-functions-datetime-quarter]]
- ==== `QUARTER`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- QUARTER(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the year quarter the date/datetime falls in.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[quarter]
- --------------------------------------------------
- [[sql-functions-today]]
- ==== `TODAY`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- TODAY()
- --------------------------------------------------
- *Input*: _none_
- *Output*: date
- .Description:
- This function offers the same functionality as <<sql-functions-current-date,CURRENT_DATE()>> function: returns
- the date when the current query reached the server. This method always returns the same value for its every occurrence
- within the same query.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[todayFunction]
- --------------------------------------------------
- Typically, this function (as well as its twin <<sql-functions-current-timestamp,CURRENT_TIMESTAMP())>> function is used
- for relative date filtering:
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[filterToday]
- --------------------------------------------------
- [[sql-functions-datetime-week]]
- ==== `WEEK_OF_YEAR/WEEK`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- WEEK_OF_YEAR(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the week of the year from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[weekOfYear]
- --------------------------------------------------
- [[sql-functions-datetime-year]]
- ==== `YEAR`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- YEAR(datetime_exp) <1>
- --------------------------------------------------
- *Input*:
- <1> date/datetime expression
- *Output*: integer
- .Description:
- Extract the year from a date/datetime.
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[year]
- --------------------------------------------------
- [[sql-functions-datetime-extract]]
- ==== `EXTRACT`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- EXTRACT(
- datetime_function <1>
- FROM datetime_exp) <2>
- --------------------------------------------------
- *Input*:
- <1> date/time function name
- <2> date/datetime expression
- *Output*: integer
- .Description:
- Extract fields from a date/datetime by specifying the name of a <<sql-functions-datetime,datetime function>>.
- The following
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[extractDayOfYear]
- --------------------------------------------------
- is the equivalent to
- [source, sql]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs/docs.csv-spec[dayOfYear]
- --------------------------------------------------
|