- Elasticsearch Guide: other versions:
- What’s new in 8.17
- Elasticsearch basics
- Quick starts
- Set up Elasticsearch
- Run Elasticsearch locally
- Installing Elasticsearch
- Configuring Elasticsearch
- Important Elasticsearch configuration
- Secure settings
- Auditing settings
- Circuit breaker settings
- Cluster-level shard allocation and routing settings
- Miscellaneous cluster settings
- Cross-cluster replication settings
- Discovery and cluster formation settings
- Field data cache settings
- Health Diagnostic settings
- Index lifecycle management settings
- Data stream lifecycle settings
- Index management settings
- Index recovery settings
- Indexing buffer settings
- License settings
- Local gateway settings
- Logging
- Machine learning settings
- Inference settings
- Monitoring settings
- Nodes
- Networking
- Node query cache settings
- Search settings
- Security settings
- Shard allocation, relocation, and recovery
- Shard request cache settings
- Snapshot and restore settings
- Transforms settings
- Thread pools
- Watcher settings
- Advanced configuration
- Important system configuration
- Bootstrap Checks
- Heap size check
- File descriptor check
- Memory lock check
- Maximum number of threads check
- Max file size check
- Maximum size virtual memory check
- Maximum map count check
- Client JVM check
- Use serial collector check
- System call filter check
- OnError and OnOutOfMemoryError checks
- Early-access check
- All permission check
- Discovery configuration check
- Bootstrap Checks for X-Pack
- Starting Elasticsearch
- Stopping Elasticsearch
- Discovery and cluster formation
- Add and remove nodes in your cluster
- Full-cluster restart and rolling restart
- Remote clusters
- Plugins
- Upgrade Elasticsearch
- Index modules
- Mapping
- Dynamic mapping
- Explicit mapping
- Runtime fields
- Field data types
- Aggregate metric
- Alias
- Arrays
- Binary
- Boolean
- Completion
- Date
- Date nanoseconds
- Dense vector
- Flattened
- Geopoint
- Geoshape
- Histogram
- IP
- Join
- Keyword
- Nested
- Numeric
- Object
- Pass-through object
- Percolator
- Point
- Range
- Rank feature
- Rank features
- Search-as-you-type
- Semantic text
- Shape
- Sparse vector
- Text
- Token count
- Unsigned long
- Version
- Metadata fields
- Mapping parameters
analyzer
coerce
copy_to
doc_values
dynamic
eager_global_ordinals
enabled
format
ignore_above
index.mapping.ignore_above
ignore_malformed
index
index_options
index_phrases
index_prefixes
meta
fields
normalizer
norms
null_value
position_increment_gap
properties
search_analyzer
similarity
store
subobjects
term_vector
- Mapping limit settings
- Removal of mapping types
- Text analysis
- Overview
- Concepts
- Configure text analysis
- Built-in analyzer reference
- Tokenizer reference
- Token filter reference
- Apostrophe
- ASCII folding
- CJK bigram
- CJK width
- Classic
- Common grams
- Conditional
- Decimal digit
- Delimited payload
- Dictionary decompounder
- Edge n-gram
- Elision
- Fingerprint
- Flatten graph
- Hunspell
- Hyphenation decompounder
- Keep types
- Keep words
- Keyword marker
- Keyword repeat
- KStem
- Length
- Limit token count
- Lowercase
- MinHash
- Multiplexer
- N-gram
- Normalization
- Pattern capture
- Pattern replace
- Phonetic
- Porter stem
- Predicate script
- Remove duplicates
- Reverse
- Shingle
- Snowball
- Stemmer
- Stemmer override
- Stop
- Synonym
- Synonym graph
- Trim
- Truncate
- Unique
- Uppercase
- Word delimiter
- Word delimiter graph
- Character filters reference
- Normalizers
- Index templates
- Data streams
- Ingest pipelines
- Example: Parse logs
- Enrich your data
- Processor reference
- Append
- Attachment
- Bytes
- Circle
- Community ID
- Convert
- CSV
- Date
- Date index name
- Dissect
- Dot expander
- Drop
- Enrich
- Fail
- Fingerprint
- Foreach
- Geo-grid
- GeoIP
- Grok
- Gsub
- HTML strip
- Inference
- IP Location
- Join
- JSON
- KV
- Lowercase
- Network direction
- Pipeline
- Redact
- Registered domain
- Remove
- Rename
- Reroute
- Script
- Set
- Set security user
- Sort
- Split
- Terminate
- Trim
- Uppercase
- URL decode
- URI parts
- User agent
- Ingest pipelines in Search
- Aliases
- Search your data
- Re-ranking
- Query DSL
- Aggregations
- Bucket aggregations
- Adjacency matrix
- Auto-interval date histogram
- Categorize text
- Children
- Composite
- Date histogram
- Date range
- Diversified sampler
- Filter
- Filters
- Frequent item sets
- Geo-distance
- Geohash grid
- Geohex grid
- Geotile grid
- Global
- Histogram
- IP prefix
- IP range
- Missing
- Multi Terms
- Nested
- Parent
- Random sampler
- Range
- Rare terms
- Reverse nested
- Sampler
- Significant terms
- Significant text
- Terms
- Time series
- Variable width histogram
- Subtleties of bucketing range fields
- Metrics aggregations
- Pipeline aggregations
- Average bucket
- Bucket script
- Bucket count K-S test
- Bucket correlation
- Bucket selector
- Bucket sort
- Change point
- Cumulative cardinality
- Cumulative sum
- Derivative
- Extended stats bucket
- Inference bucket
- Max bucket
- Min bucket
- Moving function
- Moving percentiles
- Normalize
- Percentiles bucket
- Serial differencing
- Stats bucket
- Sum bucket
- Bucket aggregations
- Geospatial analysis
- Connectors
- EQL
- ES|QL
- SQL
- Overview
- Getting Started with SQL
- Conventions and Terminology
- Security
- SQL REST API
- SQL Translate API
- SQL CLI
- SQL JDBC
- SQL ODBC
- SQL Client Applications
- SQL Language
- Functions and Operators
- Comparison Operators
- Logical Operators
- Math Operators
- Cast Operators
- LIKE and RLIKE Operators
- Aggregate Functions
- Grouping Functions
- Date/Time and Interval Functions and Operators
- Full-Text Search Functions
- Mathematical Functions
- String Functions
- Type Conversion Functions
- Geo Functions
- Conditional Functions And Expressions
- System Functions
- Reserved keywords
- SQL Limitations
- Scripting
- Data management
- ILM: Manage the index lifecycle
- Tutorial: Customize built-in policies
- Tutorial: Automate rollover
- Index management in Kibana
- Overview
- Concepts
- Index lifecycle actions
- Configure a lifecycle policy
- Migrate index allocation filters to node roles
- Troubleshooting index lifecycle management errors
- Start and stop index lifecycle management
- Manage existing indices
- Skip rollover
- Restore a managed data stream or index
- Data tiers
- Autoscaling
- Monitor a cluster
- Roll up or transform your data
- Set up a cluster for high availability
- Snapshot and restore
- Secure the Elastic Stack
- Elasticsearch security principles
- Start the Elastic Stack with security enabled automatically
- Manually configure security
- Updating node security certificates
- User authentication
- Built-in users
- Service accounts
- Internal users
- Token-based authentication services
- User profiles
- Realms
- Realm chains
- Security domains
- Active Directory user authentication
- File-based user authentication
- LDAP user authentication
- Native user authentication
- OpenID Connect authentication
- PKI user authentication
- SAML authentication
- Kerberos authentication
- JWT authentication
- Integrating with other authentication systems
- Enabling anonymous access
- Looking up users without authentication
- Controlling the user cache
- Configuring SAML single-sign-on on the Elastic Stack
- Configuring single sign-on to the Elastic Stack using OpenID Connect
- User authorization
- Built-in roles
- Defining roles
- Role restriction
- Security privileges
- Document level security
- Field level security
- Granting privileges for data streams and aliases
- Mapping users and groups to roles
- Setting up field and document level security
- Submitting requests on behalf of other users
- Configuring authorization delegation
- Customizing roles and authorization
- Enable audit logging
- Restricting connections with IP filtering
- Securing clients and integrations
- Operator privileges
- Troubleshooting
- Some settings are not returned via the nodes settings API
- Authorization exceptions
- Users command fails due to extra arguments
- Users are frequently locked out of Active Directory
- Certificate verification fails for curl on Mac
- SSLHandshakeException causes connections to fail
- Common SSL/TLS exceptions
- Common Kerberos exceptions
- Common SAML issues
- Internal Server Error in Kibana
- Setup-passwords command fails due to connection failure
- Failures due to relocation of the configuration files
- Limitations
- Watcher
- Command line tools
- elasticsearch-certgen
- elasticsearch-certutil
- elasticsearch-create-enrollment-token
- elasticsearch-croneval
- elasticsearch-keystore
- elasticsearch-node
- elasticsearch-reconfigure-node
- elasticsearch-reset-password
- elasticsearch-saml-metadata
- elasticsearch-service-tokens
- elasticsearch-setup-passwords
- elasticsearch-shard
- elasticsearch-syskeygen
- elasticsearch-users
- Optimizations
- Troubleshooting
- Fix common cluster issues
- Diagnose unassigned shards
- Add a missing tier to the system
- Allow Elasticsearch to allocate the data in the system
- Allow Elasticsearch to allocate the index
- Indices mix index allocation filters with data tiers node roles to move through data tiers
- Not enough nodes to allocate all shard replicas
- Total number of shards for an index on a single node exceeded
- Total number of shards per node has been reached
- Troubleshooting corruption
- Fix data nodes out of disk
- Fix master nodes out of disk
- Fix other role nodes out of disk
- Start index lifecycle management
- Start Snapshot Lifecycle Management
- Restore from snapshot
- Troubleshooting broken repositories
- Addressing repeated snapshot policy failures
- Troubleshooting an unstable cluster
- Troubleshooting discovery
- Troubleshooting monitoring
- Troubleshooting transforms
- Troubleshooting Watcher
- Troubleshooting searches
- Troubleshooting shards capacity health issues
- Troubleshooting an unbalanced cluster
- Capture diagnostics
- REST APIs
- API conventions
- Common options
- REST API compatibility
- Autoscaling APIs
- Behavioral Analytics APIs
- Compact and aligned text (CAT) APIs
- cat aliases
- cat allocation
- cat anomaly detectors
- cat component templates
- cat count
- cat data frame analytics
- cat datafeeds
- cat fielddata
- cat health
- cat indices
- cat master
- cat nodeattrs
- cat nodes
- cat pending tasks
- cat plugins
- cat recovery
- cat repositories
- cat segments
- cat shards
- cat snapshots
- cat task management
- cat templates
- cat thread pool
- cat trained model
- cat transforms
- Cluster APIs
- Cluster allocation explain
- Cluster get settings
- Cluster health
- Health
- Cluster reroute
- Cluster state
- Cluster stats
- Cluster update settings
- Nodes feature usage
- Nodes hot threads
- Nodes info
- Prevalidate node removal
- Nodes reload secure settings
- Nodes stats
- Cluster Info
- Pending cluster tasks
- Remote cluster info
- Task management
- Voting configuration exclusions
- Create or update desired nodes
- Get desired nodes
- Delete desired nodes
- Get desired balance
- Reset desired balance
- Cross-cluster replication APIs
- Connector APIs
- Create connector
- Delete connector
- Get connector
- List connectors
- Update connector API key id
- Update connector configuration
- Update connector index name
- Update connector features
- Update connector filtering
- Update connector name and description
- Update connector pipeline
- Update connector scheduling
- Update connector service type
- Create connector sync job
- Cancel connector sync job
- Delete connector sync job
- Get connector sync job
- List connector sync jobs
- Check in a connector
- Update connector error
- Update connector last sync stats
- Update connector status
- Check in connector sync job
- Claim connector sync job
- Set connector sync job error
- Set connector sync job stats
- Data stream APIs
- Document APIs
- Enrich APIs
- EQL APIs
- ES|QL APIs
- Features APIs
- Fleet APIs
- Graph explore API
- Index APIs
- Alias exists
- Aliases
- Analyze
- Analyze index disk usage
- Clear cache
- Clone index
- Close index
- Create index
- Create or update alias
- Create or update component template
- Create or update index template
- Create or update index template (legacy)
- Delete component template
- Delete dangling index
- Delete alias
- Delete index
- Delete index template
- Delete index template (legacy)
- Exists
- Field usage stats
- Flush
- Force merge
- Get alias
- Get component template
- Get field mapping
- Get index
- Get index settings
- Get index template
- Get index template (legacy)
- Get mapping
- Import dangling index
- Index recovery
- Index segments
- Index shard stores
- Index stats
- Index template exists (legacy)
- List dangling indices
- Open index
- Refresh
- Resolve index
- Resolve cluster
- Rollover
- Shrink index
- Simulate index
- Simulate template
- Split index
- Unfreeze index
- Update index settings
- Update mapping
- Index lifecycle management APIs
- Create or update lifecycle policy
- Get policy
- Delete policy
- Move to step
- Remove policy
- Retry policy
- Get index lifecycle management status
- Explain lifecycle
- Start index lifecycle management
- Stop index lifecycle management
- Migrate indices, ILM policies, and legacy, composable and component templates to data tiers routing
- Inference APIs
- Delete inference API
- Get inference API
- Perform inference API
- Create inference API
- Stream inference API
- Update inference API
- AlibabaCloud AI Search inference service
- Amazon Bedrock inference service
- Anthropic inference service
- Azure AI studio inference service
- Azure OpenAI inference service
- Cohere inference service
- Elasticsearch inference service
- ELSER inference service
- Google AI Studio inference service
- Google Vertex AI inference service
- HuggingFace inference service
- Mistral inference service
- OpenAI inference service
- Watsonx inference service
- Info API
- Ingest APIs
- Licensing APIs
- Logstash APIs
- Machine learning APIs
- Machine learning anomaly detection APIs
- Add events to calendar
- Add jobs to calendar
- Close jobs
- Create jobs
- Create calendars
- Create datafeeds
- Create filters
- Delete calendars
- Delete datafeeds
- Delete events from calendar
- Delete filters
- Delete forecasts
- Delete jobs
- Delete jobs from calendar
- Delete model snapshots
- Delete expired data
- Estimate model memory
- Flush jobs
- Forecast jobs
- Get buckets
- Get calendars
- Get categories
- Get datafeeds
- Get datafeed statistics
- Get influencers
- Get jobs
- Get job statistics
- Get model snapshots
- Get model snapshot upgrade statistics
- Get overall buckets
- Get scheduled events
- Get filters
- Get records
- Open jobs
- Post data to jobs
- Preview datafeeds
- Reset jobs
- Revert model snapshots
- Start datafeeds
- Stop datafeeds
- Update datafeeds
- Update filters
- Update jobs
- Update model snapshots
- Upgrade model snapshots
- Machine learning data frame analytics APIs
- Create data frame analytics jobs
- Delete data frame analytics jobs
- Evaluate data frame analytics
- Explain data frame analytics
- Get data frame analytics jobs
- Get data frame analytics jobs stats
- Preview data frame analytics
- Start data frame analytics jobs
- Stop data frame analytics jobs
- Update data frame analytics jobs
- Machine learning trained model APIs
- Clear trained model deployment cache
- Create or update trained model aliases
- Create part of a trained model
- Create trained models
- Create trained model vocabulary
- Delete trained model aliases
- Delete trained models
- Get trained models
- Get trained models stats
- Infer trained model
- Start trained model deployment
- Stop trained model deployment
- Update trained model deployment
- Migration APIs
- Node lifecycle APIs
- Query rules APIs
- Reload search analyzers API
- Repositories metering APIs
- Rollup APIs
- Root API
- Script APIs
- Search APIs
- Search Application APIs
- Searchable snapshots APIs
- Security APIs
- Authenticate
- Change passwords
- Clear cache
- Clear roles cache
- Clear privileges cache
- Clear API key cache
- Clear service account token caches
- Create API keys
- Create or update application privileges
- Create or update role mappings
- Create or update roles
- Bulk create or update roles API
- Bulk delete roles API
- Create or update users
- Create service account tokens
- Delegate PKI authentication
- Delete application privileges
- Delete role mappings
- Delete roles
- Delete service account token
- Delete users
- Disable users
- Enable users
- Enroll Kibana
- Enroll node
- Get API key information
- Get application privileges
- Get builtin privileges
- Get role mappings
- Get roles
- Query Role
- Get service accounts
- Get service account credentials
- Get Security settings
- Get token
- Get user privileges
- Get users
- Grant API keys
- Has privileges
- Invalidate API key
- Invalidate token
- OpenID Connect prepare authentication
- OpenID Connect authenticate
- OpenID Connect logout
- Query API key information
- Query User
- Update API key
- Update Security settings
- Bulk update API keys
- SAML prepare authentication
- SAML authenticate
- SAML logout
- SAML invalidate
- SAML complete logout
- SAML service provider metadata
- SSL certificate
- Activate user profile
- Disable user profile
- Enable user profile
- Get user profiles
- Suggest user profile
- Update user profile data
- Has privileges user profile
- Create Cross-Cluster API key
- Update Cross-Cluster API key
- Snapshot and restore APIs
- Snapshot lifecycle management APIs
- SQL APIs
- Synonyms APIs
- Text structure APIs
- Transform APIs
- Usage API
- Watcher APIs
- Definitions
- Migration guide
- Release notes
- Elasticsearch version 8.18.0
- Elasticsearch version 8.17.0
- Elasticsearch version 8.16.1
- Elasticsearch version 8.16.0
- Elasticsearch version 8.15.5
- Elasticsearch version 8.15.4
- Elasticsearch version 8.15.3
- Elasticsearch version 8.15.2
- Elasticsearch version 8.15.1
- Elasticsearch version 8.15.0
- Elasticsearch version 8.14.3
- Elasticsearch version 8.14.2
- Elasticsearch version 8.14.1
- Elasticsearch version 8.14.0
- Elasticsearch version 8.13.4
- Elasticsearch version 8.13.3
- Elasticsearch version 8.13.2
- Elasticsearch version 8.13.1
- Elasticsearch version 8.13.0
- Elasticsearch version 8.12.2
- Elasticsearch version 8.12.1
- Elasticsearch version 8.12.0
- Elasticsearch version 8.11.4
- Elasticsearch version 8.11.3
- Elasticsearch version 8.11.2
- Elasticsearch version 8.11.1
- Elasticsearch version 8.11.0
- Elasticsearch version 8.10.4
- Elasticsearch version 8.10.3
- Elasticsearch version 8.10.2
- Elasticsearch version 8.10.1
- Elasticsearch version 8.10.0
- Elasticsearch version 8.9.2
- Elasticsearch version 8.9.1
- Elasticsearch version 8.9.0
- Elasticsearch version 8.8.2
- Elasticsearch version 8.8.1
- Elasticsearch version 8.8.0
- Elasticsearch version 8.7.1
- Elasticsearch version 8.7.0
- Elasticsearch version 8.6.2
- Elasticsearch version 8.6.1
- Elasticsearch version 8.6.0
- Elasticsearch version 8.5.3
- Elasticsearch version 8.5.2
- Elasticsearch version 8.5.1
- Elasticsearch version 8.5.0
- Elasticsearch version 8.4.3
- Elasticsearch version 8.4.2
- Elasticsearch version 8.4.1
- Elasticsearch version 8.4.0
- Elasticsearch version 8.3.3
- Elasticsearch version 8.3.2
- Elasticsearch version 8.3.1
- Elasticsearch version 8.3.0
- Elasticsearch version 8.2.3
- Elasticsearch version 8.2.2
- Elasticsearch version 8.2.1
- Elasticsearch version 8.2.0
- Elasticsearch version 8.1.3
- Elasticsearch version 8.1.2
- Elasticsearch version 8.1.1
- Elasticsearch version 8.1.0
- Elasticsearch version 8.0.1
- Elasticsearch version 8.0.0
- Elasticsearch version 8.0.0-rc2
- Elasticsearch version 8.0.0-rc1
- Elasticsearch version 8.0.0-beta1
- Elasticsearch version 8.0.0-alpha2
- Elasticsearch version 8.0.0-alpha1
- Dependencies and versions
Date/Time and Interval Functions and Operators
editDate/Time and Interval Functions and Operators
editElasticsearch SQL offers a wide range of facilities for performing date/time manipulations.
Intervals
editA 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 Elasticsearch and Elasticsearch SQL.
Elasticsearch has comprehensive support for date math both inside index names and queries.
Inside Elasticsearch 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 Elasticsearch and Elasticsearch SQL:
Elasticsearch |
Elasticsearch SQL |
Index/Table datetime math |
|
|
|
Query date/time math |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INTERVAL
allows either YEAR
and MONTH
to be mixed together or DAY
, HOUR
, MINUTE
and SECOND
.
Elasticsearch SQL accepts also the plural for each time unit (e.g. both YEAR
and YEARS
are valid).
Example of the possible combinations below:
Interval |
Description |
|
1 year and 2 months |
|
3 days and 4 hours |
|
5 days, 6 hours and 12 minutes |
|
3 days, 4 hours, 56 minutes and 1 second |
|
2 days, 3 hours, 45 minutes, 1 second and 234567890 nanoseconds |
|
123 hours and 45 minutes |
|
65 hours, 43 minutes, 21 seconds and 12300000 nanoseconds |
|
45 minutes, 1 second and 230000000 nanoseconds |
Comparison
editDate/time fields can be compared to date math expressions with the equality (=
) and IN
operators:
SELECT hire_date FROM emp WHERE hire_date = '1987-03-01||+4y/y'; hire_date ------------------------ 1991-01-26T00:00:00.000Z 1991-10-22T00:00:00.000Z 1991-09-01T00:00:00.000Z 1991-06-26T00:00:00.000Z 1991-08-30T00:00:00.000Z 1991-12-01T00:00:00.000Z
SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z
Operators
editBasic arithmetic operators (+
, -
, *
) support date/time parameters as indicated below:
SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:00
SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z
SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-1
SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:00
SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z
SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-0
Functions
editFunctions that target date/time.
CURRENT_DATE/CURDATE
editSynopsis:
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()
.
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.
SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-12
SELECT CURRENT_DATE() AS result; result ------------------------ 2018-12-12
SELECT CURDATE() AS result; result ------------------------ 2018-12-12
Typically, this function (as well as its twin TODAY()) function is used for relative date filtering:
SELECT first_name FROM emp WHERE hire_date > TODAY() - INTERVAL 35 YEARS ORDER BY first_name ASC LIMIT 5; first_name ------------ Alejandro Amabile Anoosh Basil Brendon
CURRENT_TIME/CURTIME
editSynopsis:
Input:
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.
SELECT CURRENT_TIME AS result; result ------------------------ 12:31:27.237Z
SELECT CURRENT_TIME() AS result; result ------------------------ 12:31:27.237Z
SELECT CURTIME() AS result; result ------------------------ 12:31:27.237Z
SELECT CURRENT_TIME(1) AS result; result ------------------------ 12:31:27.2Z
Typically, this function is used for relative date/time filtering:
SELECT first_name FROM emp WHERE CAST(hire_date AS TIME) > CURRENT_TIME() - INTERVAL 20 MINUTES ORDER BY first_name ASC LIMIT 5; first_name --------------- Alejandro Amabile Anneke Anoosh Arumugam
Currently, using a precision greater than 6 doesn’t make any difference to the output of the function as the maximum number of second fractional digits returned is 6.
CURRENT_TIMESTAMP
editSynopsis:
Input:
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.
SELECT CURRENT_TIMESTAMP AS result; result ------------------------ 2018-12-12T14:48:52.448Z
SELECT CURRENT_TIMESTAMP() AS result; result ------------------------ 2018-12-12T14:48:52.448Z
SELECT CURRENT_TIMESTAMP(1) AS result; result ------------------------ 2018-12-12T14:48:52.4Z
Typically, this function (as well as its twin NOW()) function is used for relative date/time filtering:
SELECT first_name FROM emp WHERE hire_date > NOW() - INTERVAL 100 YEARS ORDER BY first_name ASC LIMIT 5; first_name --------------- Alejandro Amabile Anneke Anoosh Arumugam
Currently, using a precision greater than 6 doesn’t make any difference to the output of the function as the maximum number of second fractional digits returned is 6.
DATE_ADD/DATEADD/TIMESTAMP_ADD/TIMESTAMPADD
editSynopsis:
Input:
string expression denoting the date/time unit to add to the date/datetime.
If |
|
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. If |
|
date/datetime expression. If |
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 the second argument is a long there is possibility of truncation since an integer value will be extracted and used from that long.
Datetime units to add/subtract | |
---|---|
unit |
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 |
SELECT DATE_ADD('years', 10, '2019-09-04T11:22:33.000Z'::datetime) AS "+10 years"; +10 years ------------------------ 2029-09-04T11:22:33.000Z
SELECT DATE_ADD('week', 10, '2019-09-04T11:22:33.000Z'::datetime) AS "+10 weeks"; +10 weeks ------------------------ 2019-11-13T11:22:33.000Z
SELECT DATE_ADD('seconds', -1234, '2019-09-04T11:22:33.000Z'::datetime) AS "-1234 seconds"; -1234 seconds ------------------------ 2019-09-04T11:01:59.000Z
SELECT DATE_ADD('qq', -417, '2019-09-04'::date) AS "-417 quarters"; -417 quarters ------------------------ 1915-06-04T00:00:00.000Z
SELECT DATE_ADD('minutes', 9235, '2019-09-04'::date) AS "+9235 minutes"; +9235 minutes ------------------------ 2019-09-10T09:55:00.000Z
DATE_DIFF/DATEDIFF/TIMESTAMP_DIFF/TIMESTAMPDIFF
editSynopsis:
Input:
string expression denoting the date/time unit difference between the
following two date/datetime expressions. If |
|
start date/datetime expression. If |
|
end date/datetime expression. If |
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.
Datetime difference units | |
---|---|
unit |
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 |
SELECT DATE_DIFF('years', '2019-09-04T11:22:33.000Z'::datetime, '2032-09-04T22:33:11.000Z'::datetime) AS "diffInYears"; diffInYears ------------------------ 13
SELECT DATE_DIFF('week', '2019-09-04T11:22:33.000Z'::datetime, '2016-12-08T22:33:11.000Z'::datetime) AS "diffInWeeks"; diffInWeeks ------------------------ -143
SELECT DATE_DIFF('seconds', '2019-09-04T11:22:33.123Z'::datetime, '2019-07-12T22:33:11.321Z'::datetime) AS "diffInSeconds"; diffInSeconds ------------------------ -4625362
SELECT DATE_DIFF('qq', '2019-09-04'::date, '2025-04-25'::date) AS "diffInQuarters"; diffInQuarters ------------------------ 23
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.
SELECT DATEDIFF('hours', '2019-11-10T12:10:00.000Z'::datetime, '2019-11-10T23:59:59.999Z'::datetime) AS "diffInHours"; diffInHours ------------------------ 11
SELECT DATEDIFF('minute', '2019-11-10T12:10:00.000Z'::datetime, '2019-11-10T12:15:59.999Z'::datetime) AS "diffInMinutes"; diffInMinutes ------------------------ 5
SELECT DATE_DIFF('minutes', '2019-09-04'::date, '2015-08-17T22:33:11.567Z'::datetime) AS "diffInMinutes"; diffInMinutes ------------------------ -2128407
DATE_FORMAT
editSynopsis:
Input:
date/datetime/time expression. If |
|
format pattern. If |
Output: string
Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting pattern is one of the specifiers used in the MySQL DATE_FORMAT() function.
If the 1st argument is of type time
, then pattern specified by the 2nd argument cannot contain date related units
(e.g. dd, MM, yyyy, etc.). If it contains such units an error is returned.
Ranges for month and day specifiers (%c, %D, %d, %e, %m) start at one, unlike MySQL, where they start at zero, due to
the fact that MySQL permits the storing of incomplete dates such as 2014-00-00.
Elasticsearch in this case returns an error.
SELECT DATE_FORMAT(CAST('2020-04-05' AS DATE), '%d/%m/%Y') AS "date"; date ------------------ 05/04/2020
SELECT DATE_FORMAT(CAST('2020-04-05T11:22:33.987654' AS DATETIME), '%d/%m/%Y %H:%i:%s.%f') AS "datetime"; datetime ------------------ 05/04/2020 11:22:33.987654
SELECT DATE_FORMAT(CAST('23:22:33.987' AS TIME), '%H %i %s.%f') AS "time"; time ------------------ 23 22 33.987000
DATE_PARSE
editSynopsis:
Input:
date expression as a string. If |
|
parsing pattern. If |
Output: date
Description: Returns a date by parsing the 1st argument using the format specified in the 2nd argument. The parsing
format pattern used is the one from
java.time.format.DateTimeFormatter
.
If the parsing pattern does not contain all valid date units (e.g. HH:mm:ss, dd-MM HH:mm:ss, etc.) an error is returned
as the function needs to return a value of date
type which will contain date part.
SELECT DATE_PARSE('07/04/2020', 'dd/MM/yyyy') AS "date"; date ----------- 2020-04-07
DATETIME_FORMAT
editSynopsis:
Input:
date/datetime/time expression. If |
|
format pattern. If |
Output: string
Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting
pattern used is the one from
java.time.format.DateTimeFormatter
.
If the 1st argument is of type time
, then pattern specified by the 2nd argument cannot contain date related units
(e.g. dd, MM, yyyy, etc.). If it contains such units an error is returned.
SELECT DATETIME_FORMAT(CAST('2020-04-05' AS DATE), 'dd/MM/yyyy') AS "date"; date ------------------ 05/04/2020
SELECT DATETIME_FORMAT(CAST('2020-04-05T11:22:33.987654' AS DATETIME), 'dd/MM/yyyy HH:mm:ss.SS') AS "datetime"; datetime ------------------ 05/04/2020 11:22:33.98
SELECT DATETIME_FORMAT(CAST('11:22:33.987' AS TIME), 'HH mm ss.S') AS "time"; time ------------------ 11 22 33.9
DATETIME_PARSE
editSynopsis:
Input:
datetime expression as a string. If |
|
parsing pattern. If |
Output: datetime
Description: Returns a datetime by parsing the 1st argument using the format specified in the 2nd argument. The parsing
format pattern used is the one from
java.time.format.DateTimeFormatter
.
If the parsing pattern contains only date or only time units (e.g. dd/MM/yyyy, HH:mm:ss, etc.) an error is returned
as the function needs to return a value of datetime
type which must contain both.
SELECT DATETIME_PARSE('07/04/2020 10:20:30.123', 'dd/MM/yyyy HH:mm:ss.SSS') AS "datetime"; datetime ------------------------ 2020-04-07T10:20:30.123Z
SELECT DATETIME_PARSE('10:20:30 07/04/2020 Europe/Berlin', 'HH:mm:ss dd/MM/yyyy VV') AS "datetime"; datetime ------------------------ 2020-04-07T08:20:30.000Z
If timezone is not specified in the datetime string expression and the parsing pattern, the resulting datetime
will have the
time zone specified by the user through the time_zone
/timezone
REST/driver parameters
with no conversion applied.
{ "query" : "SELECT DATETIME_PARSE('10:20:30 07/04/2020', 'HH:mm:ss dd/MM/yyyy') AS \"datetime\"", "time_zone" : "Europe/Athens" } datetime ----------------------------- 2020-04-07T10:20:30.000+03:00
TIME_PARSE
editSynopsis:
Input:
time expression as a string. If |
|
parsing pattern. If |
Output: time
Description: Returns a time by parsing the 1st argument using the format specified in the 2nd argument. The parsing
format pattern used is the one from
java.time.format.DateTimeFormatter
.
If the parsing pattern contains only date units (e.g. dd/MM/yyyy) an error is returned
as the function needs to return a value of time
type which will contain only time.
SELECT TIME_PARSE('10:20:30.123', 'HH:mm:ss.SSS') AS "time"; time --------------- 10:20:30.123Z
SELECT TIME_PARSE('10:20:30-01:00', 'HH:mm:ssXXX') AS "time"; time --------------- 11:20:30.000Z
If timezone is not specified in the time string expression and the parsing pattern,
the resulting time
will have the offset of the time zone specified by the user through the
time_zone
/timezone
REST/driver
parameters at the Unix epoch date (1970-01-01
) with no conversion applied.
{ "query" : "SELECT DATETIME_PARSE('10:20:30', 'HH:mm:ss') AS \"time\"", "time_zone" : "Europe/Athens" } time ------------------------------------ 10:20:30.000+02:00
DATE_PART/DATEPART
editSynopsis:
Input:
string expression denoting the unit to extract from the date/datetime. If
|
|
date/datetime expression. If |
Output: integer
Description: Extract the specified unit from a date/datetime. It’s similar to
EXTRACT
but with different names and aliases for the
units and provides more options (e.g.: TZOFFSET
).
Datetime units to extract | |
---|---|
unit |
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 |
SELECT DATE_PART('year', '2019-09-22T11:22:33.123Z'::datetime) AS "years"; years ---------- 2019
SELECT DATE_PART('mi', '2019-09-04T11:22:33.123Z'::datetime) AS mins; mins ----------- 22
SELECT DATE_PART('quarters', CAST('2019-09-24' AS DATE)) AS quarter; quarter ------------- 3
SELECT DATE_PART('month', CAST('2019-09-24' AS DATE)) AS month; month ------------- 9
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.
SELECT DATE_PART('week', '2019-09-22T11:22:33.123Z'::datetime) AS week; week ---------- 39
The tzoffset
returns the total number of minutes (signed) that represent the time zone’s offset.
SELECT DATE_PART('tzoffset', '2019-09-04T11:22:33.123+05:15'::datetime) AS tz_mins; tz_mins -------------- 315
SELECT DATE_PART('tzoffset', '2019-09-04T11:22:33.123-03:49'::datetime) AS tz_mins; tz_mins -------------- -229
DATE_TRUNC/DATETRUNC
editSynopsis:
Input:
string expression denoting the unit to which the date/datetime/interval
should be truncated to. If |
|
date/datetime/interval expression. If |
Output: datetime/interval
Description: Truncate the date/datetime/interval 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 the first argument is week
and the
second argument is of interval
type, an error is thrown since the interval
data type doesn’t support a week
time unit.
Datetime truncation units | |
---|---|
unit |
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 |
SELECT DATE_TRUNC('millennium', '2019-09-04T11:22:33.123Z'::datetime) AS millennium; millennium ------------------------ 2000-01-01T00:00:00.000Z
SELECT DATETRUNC('week', '2019-08-24T11:22:33.123Z'::datetime) AS week; week ------------------------ 2019-08-19T00:00:00.000Z
SELECT DATE_TRUNC('mi', '2019-09-04T11:22:33.123Z'::datetime) AS mins; mins ------------------------ 2019-09-04T11:22:00.000Z
SELECT DATE_TRUNC('decade', CAST('2019-09-04' AS DATE)) AS decades; decades ------------------------ 2010-01-01T00:00:00.000Z
SELECT DATETRUNC('quarters', CAST('2019-09-04' AS DATE)) AS quarter; quarter ------------------------ 2019-07-01T00:00:00.000Z
SELECT DATE_TRUNC('centuries', INTERVAL '199-5' YEAR TO MONTH) AS centuries; centuries ------------------ +100-0
SELECT DATE_TRUNC('hours', INTERVAL '17 22:13:12' DAY TO SECONDS) AS hour; hour ------------------ +17 22:00:00
SELECT DATE_TRUNC('days', INTERVAL '19 15:24:19' DAY TO SECONDS) AS day; day ------------------ +19 00:00:00
FORMAT
editSynopsis:
Input:
date/datetime/time expression. If |
|
format pattern. If |
Output: string
Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting pattern used is the one from Microsoft SQL Server Format Specification.
If the 1st argument is of type time
, then pattern specified by the 2nd argument cannot contain date related units
(e.g. dd, MM, yyyy, etc.). If it contains such units an error is returned.
Format specifier F
will be working similar to format specifier f
.
It will return the fractional part of seconds, and the number of digits will be same as of the number of Fs
provided as input (up to 9 digits).
Result will contain 0
appended in the end to match with number of F
provided.
e.g.: for a time part 10:20:30.1234
and pattern HH:mm:ss.FFFFFF
, the output string of the function would be: 10:20:30.123400
.
Format specifier y
will return year-of-era instead of one/two low-order digits.
eg.: For year 2009
, y
will be returning 2009
instead of 9
. For year 43
, y
format specifier will return 43
.
- Special characters like "
, \
and %
will be returned as it is without any change. eg.: formatting date 17-sep-2020
with %M
will return %9
SELECT FORMAT(CAST('2020-04-05' AS DATE), 'dd/MM/yyyy') AS "date"; date ------------------ 05/04/2020
SELECT FORMAT(CAST('2020-04-05T11:22:33.987654' AS DATETIME), 'dd/MM/yyyy HH:mm:ss.ff') AS "datetime"; datetime ------------------ 05/04/2020 11:22:33.98
SELECT FORMAT(CAST('11:22:33.987' AS TIME), 'HH mm ss.f') AS "time"; time ------------------ 11 22 33.9
TO_CHAR
editSynopsis:
Input:
date/datetime/time expression. If |
|
format pattern. If |
Output: string
Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting pattern conforms to PostgreSQL Template Patterns for Date/Time Formatting.
If the 1st argument is of type time
, then the pattern specified by the 2nd argument cannot contain date related units
(e.g. dd, MM, YYYY, etc.). If it contains such units an error is returned.
The result of the patterns TZ
and tz
(time zone abbreviations) in some cases differ from the results returned by the TO_CHAR
in PostgreSQL. The reason is that the time zone abbreviations specified by the JDK are different from the ones specified by PostgreSQL.
This function might show an actual time zone abbreviation instead of the generic LMT
or empty string or offset returned by the PostgreSQL
implementation. The summer/daylight markers might also differ between the two implementations (e.g. will show HT
instead of HST
for Hawaii).
The FX
, TM
, SP
pattern modifiers are not supported and will show up as FX
, TM
, SP
literals in the output.
SELECT TO_CHAR(CAST('2020-04-05' AS DATE), 'DD/MM/YYYY') AS "date"; date ------------------ 05/04/2020
SELECT TO_CHAR(CAST('2020-04-05T11:22:33.987654' AS DATETIME), 'DD/MM/YYYY HH24:MI:SS.FF2') AS "datetime"; datetime ------------------ 05/04/2020 11:22:33.98
SELECT TO_CHAR(CAST('23:22:33.987' AS TIME), 'HH12 MI SS.FF1') AS "time"; time ------------------ 11 22 33.9
DAY_OF_MONTH/DOM/DAY
editSynopsis:
Input:
Output: integer
Description: Extract the day of the month from a date/datetime.
SELECT DAY_OF_MONTH(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- 19
DAY_OF_WEEK/DAYOFWEEK/DOW
editSynopsis:
Input:
Output: integer
Description: Extract the day of the week from a date/datetime. Sunday is 1
, Monday is 2
, etc.
SELECT DAY_OF_WEEK(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- 2
DAY_OF_YEAR/DOY
editSynopsis:
Input:
Output: integer
Description: Extract the day of the year from a date/datetime.
SELECT DAY_OF_YEAR(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- 50
DAY_NAME/DAYNAME
editSynopsis:
Input:
Output: string
Description: Extract the day of the week from a date/datetime in text format (Monday
, Tuesday
…).
SELECT DAY_NAME(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- Monday
HOUR_OF_DAY/HOUR
editSynopsis:
Input:
Output: integer
Description: Extract the hour of the day from a date/datetime.
SELECT HOUR_OF_DAY(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS hour; hour --------------- 10
ISO_DAY_OF_WEEK/ISODAYOFWEEK/ISODOW/IDOW
editSynopsis:
Input:
Output: integer
Description: Extract the day of the week from a date/datetime, following the ISO 8601 standard.
Monday is 1
, Tuesday is 2
, etc.
SELECT ISO_DAY_OF_WEEK(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- 1
ISO_WEEK_OF_YEAR/ISOWEEKOFYEAR/ISOWEEK/IWOY/IW
editSynopsis:
Input:
Output: integer
Description: Extract the week of the year from a date/datetime, following ISO 8601 standard. The first week of a year is the first week with a majority (4 or more) of its days in January.
SELECT ISO_WEEK_OF_YEAR(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS week; week --------------- 8
MINUTE_OF_DAY
editSynopsis:
Input:
Output: integer
Description: Extract the minute of the day from a date/datetime.
SELECT MINUTE_OF_DAY(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS minute; minute --------------- 623
MINUTE_OF_HOUR/MINUTE
editSynopsis:
Input:
Output: integer
Description: Extract the minute of the hour from a date/datetime.
SELECT MINUTE_OF_HOUR(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS minute; minute --------------- 23
MONTH_OF_YEAR/MONTH
editSynopsis:
Input:
Output: integer
Description: Extract the month of the year from a date/datetime.
SELECT MONTH_OF_YEAR(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS month; month --------------- 2
MONTH_NAME/MONTHNAME
editSynopsis:
Input:
Output: string
Description: Extract the month from a date/datetime in text format (January
, February
…).
SELECT MONTH_NAME(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS month; month --------------- February
NOW
editSynopsis:
NOW()
Input: none
Output: datetime
Description: This function offers the same functionality as 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.
SELECT NOW() AS result; result ------------------------ 2018-12-12T14:48:52.448Z
Typically, this function (as well as its twin CURRENT_TIMESTAMP()) function is used for relative date/time filtering:
SELECT first_name FROM emp WHERE hire_date > NOW() - INTERVAL 100 YEARS ORDER BY first_name ASC LIMIT 5; first_name --------------- Alejandro Amabile Anneke Anoosh Arumugam
SECOND_OF_MINUTE/SECOND
editSynopsis:
Input:
Output: integer
Description: Extract the second of the minute from a date/datetime.
SELECT SECOND_OF_MINUTE(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS second; second --------------- 27
QUARTER
editSynopsis:
Input:
Output: integer
Description: Extract the year quarter the date/datetime falls in.
SELECT QUARTER(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS quarter; quarter --------------- 1
TODAY
editSynopsis:
TODAY()
Input: none
Output: date
Description: This function offers the same functionality as 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.
SELECT TODAY() AS result; result ------------------------ 2018-12-12
Typically, this function (as well as its twin CURRENT_TIMESTAMP()) function is used for relative date filtering:
SELECT first_name FROM emp WHERE hire_date > TODAY() - INTERVAL 35 YEARS ORDER BY first_name ASC LIMIT 5; first_name ------------ Alejandro Amabile Anoosh Basil Brendon
WEEK_OF_YEAR/WEEK
editSynopsis:
Input:
Output: integer
Description: Extract the week of the year from a date/datetime.
SELECT WEEK(CAST('1988-01-05T09:22:10Z' AS TIMESTAMP)) AS week, ISOWEEK(CAST('1988-01-05T09:22:10Z' AS TIMESTAMP)) AS isoweek; week | isoweek ---------------+--------------- 2 |1
YEAR
editSynopsis:
Input:
Output: integer
Description: Extract the year from a date/datetime.
SELECT YEAR(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS year; year --------------- 2018
EXTRACT
editSynopsis:
Input:
Output: integer
Description: Extract fields from a date/datetime by specifying the name of a datetime function. The following
SELECT EXTRACT(DAY_OF_YEAR FROM CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- 50
is the equivalent to
SELECT DAY_OF_YEAR(CAST('2018-02-19T10:23:27Z' AS TIMESTAMP)) AS day; day --------------- 50
On this page
- Intervals
- Comparison
- Operators
- Functions
CURRENT_DATE/CURDATE
CURRENT_TIME/CURTIME
CURRENT_TIMESTAMP
DATE_ADD/DATEADD/TIMESTAMP_ADD/TIMESTAMPADD
DATE_DIFF/DATEDIFF/TIMESTAMP_DIFF/TIMESTAMPDIFF
DATE_FORMAT
DATE_PARSE
DATETIME_FORMAT
DATETIME_PARSE
TIME_PARSE
DATE_PART/DATEPART
DATE_TRUNC/DATETRUNC
FORMAT
TO_CHAR
DAY_OF_MONTH/DOM/DAY
DAY_OF_WEEK/DAYOFWEEK/DOW
DAY_OF_YEAR/DOY
DAY_NAME/DAYNAME
HOUR_OF_DAY/HOUR
ISO_DAY_OF_WEEK/ISODAYOFWEEK/ISODOW/IDOW
ISO_WEEK_OF_YEAR/ISOWEEKOFYEAR/ISOWEEK/IWOY/IW
MINUTE_OF_DAY
MINUTE_OF_HOUR/MINUTE
MONTH_OF_YEAR/MONTH
MONTH_NAME/MONTHNAME
NOW
SECOND_OF_MINUTE/SECOND
QUARTER
TODAY
WEEK_OF_YEAR/WEEK
YEAR
EXTRACT
ElasticON events are back!
Learn about the Elastic Search AI Platform from the experts at our live events.
Register now