LogoLogo
  • Welcome to e6data
  • Introduction to e6data
    • Concepts
    • Architecture
      • e6data in VPC Deployment Model
      • Connect to e6data serverless compute
  • Get Started
  • Sign Up
  • Setup
    • AWS Setup
      • In VPC Deployment (AWS)
        • Prerequisite Infrastructure
        • Infrastructure & Permissions for e6data
        • Setup Kubernetes Components
        • Setup using Terraform in AWS
          • Update a AWS Terraform for your Workspace
        • AWS PrivateLink and e6data
        • VPC Peering | e6data on AWS
      • Connect to e6data serverless compute (AWS)
        • Workspace Creation
        • Catalog Creation
          • Glue Metastore
          • Hive Metastore
          • Unity Catalog
        • Cluster Creation
    • GCP Setup
      • In VPC Deployment (GCP)
        • Prerequisite Infrastructure
        • Infrastructure & Permissions for e6data
        • Setup Kubernetes Components
        • Setup using Terraform in GCP
        • Update a GCP Terraform for your Workspace
      • Connect to e6data serverless compute (GCP)
    • Azure Setup
      • Prerequisite Infrastructure
      • Infrastructure & Permissions for e6data
      • Setup Kubernetes Components
      • Setup using Terraform in AZURE
        • Update a AZURE Terraform for your Workspace
  • Workspaces
    • Create Workspaces
    • Enable/Disable Workspaces
    • Update a Workspace
    • Delete a Workspace
  • Catalogs
    • Create Catalogs
      • Hive Metastore
        • Connect to a Hive Metastore
        • Edit a Hive Metastore Connection
        • Delete a Hive Metastore Connection
      • Glue Metastore
        • Connect to a Glue Metastore
        • Edit a Glue Metastore Connection
        • Delete a Glue Metastore Connection
      • Unity Catalog
        • Connect to Unity Catalog
        • Edit Unity Catalog
        • Delete Unity Catalog
      • Cross-account Catalog Access
        • Configure Cross-account Catalog to Access AWS Hive Metastore
        • Configure Cross-account Catalog to Access Unity Catalog
        • Configure Cross-account Catalog to Access AWS Glue
        • Configure Cross-account Catalog to Access GCP Hive Metastore
    • Manage Catalogs
    • Privileges
      • Access Control
      • Column Masking
      • Row Filter
  • Clusters
    • Edit & Delete Clusters
    • Suspend & Resume Clusters
    • Cluster Size
    • Load Based Sizing
    • Auto Suspension
    • Query Timeout
    • Monitoring
    • Connection Info
  • Pools
    • Delete Pools
  • Query Editor
    • Editor Pane
    • Results Pane
    • Schema Explorer
    • Data Preview
  • Notebook
    • Editor Pane
    • Results Pane
    • Schema Explorer
    • Data Preview
  • Query History
    • Query Count API
  • Connectivity
    • IP Sets
    • Endpoints
    • Cloud Resources
    • Network Firewall
  • Access Control
    • Users
    • Groups
    • Roles
      • Permissions
      • Policies
    • Single Sign-On (SSO)
      • AWS SSO
      • Okta
      • Microsoft My Apps-SSO
      • Icons for IdP
    • Service Accounts
    • Multi-Factor Authentication (Beta)
  • Usage and Cost Management
  • Audit Log
  • User Settings
    • Profile
    • Personal Access Tokens (PAT)
  • Advanced Features
    • Cross-Catalog & Cross-Schema Querying
  • Supported Data Types
  • SQL Command Reference
    • Query Syntax
      • General functions
    • Aggregate Functions
    • Mathematical Functions & Operators
      • Arithematic Operators
      • Rounding and Truncation Functions
      • Exponential and Root Functions
      • Trigonometric Functions
      • Logarithmic Functions
    • String Functions
    • Date-Time Functions
      • Constant Functions
      • Conversion Functions
      • Date Truncate Function
      • Addition and Subtraction Functions
      • Extraction Functions
      • Format Functions
      • Timezone Functions
    • Conditional Expressions
    • Conversion Functions
    • Window Functions
    • Comparison Operators & Functions
    • Logical Operators
    • Statistical Functions
    • Bitwise Functions
    • Array Functions
    • Regular Expression Functions
    • Generate Functions
    • Cardinality Estimation Functions
    • JSON Functions
    • Checksum Functions
    • Unload Function (Copy into)
    • Struct Functions
  • Equivalent Functions & Operators
  • Connectors & Drivers
    • DBeaver
    • DbVisualiser
    • Apache Superset
    • Jupyter Notebook
    • Tableau Cloud
    • Tableau Desktop
    • Power BI
    • Metabase
    • Zeppelin
    • Python Connector
      • Code Samples
    • JDBC Driver
      • Code Samples
      • API Support
    • Configure Cluster Ingress
      • ALB Ingress in Kubernetes
      • GCE Ingress in Kubernetes
      • Ingress-Nginx in Kubernetes
  • Security & Trust
    • Best Practices
      • AWS Best Practices
    • Features & Responsibilities Matrix
    • Data Protection Addendum(DPA)
  • Tutorials and Best Practices
    • How to configure HIVE metastore if you don't have one?
    • How-To Videos
  • Known Limitations
    • SQL Limitations
    • Other Limitations
    • Restart Triggers
    • Cloud Provider Limitations
  • Error Codes
    • General Errors
    • User Account Errors
    • Workspace Errors
    • Catalog Errors
    • Cluster Errors
    • Data Governance Errors
    • Query History Errors
    • Query Editor Errors
    • Pool Errors
    • Connectivity Errors
  • Terms & Condition
  • Privacy Policy
    • Cookie Policy
  • FAQs
    • Workspace Setup
    • Security
    • Catalog Privileges
  • Services Utilised for e6data Deployment
    • AWS supported regions
    • GCP supported regions
    • AZURE supported regions
  • Release Notes & Updates
    • 6th Sept 2024
    • 6th June 2024
    • 18th April 2024
    • 9th April 2024
    • 30th March 2024
    • 16th March 2024
    • 14th March 2024
    • 12th March 2024
    • 2nd March 2024
    • 10th February 2024
    • 3rd February 2024
    • 17th January 2024
    • 9th January 2024
    • 3rd January 2024
    • 18th December 2023
    • 12th December 2023
    • 9th December 2023
    • 4th December 2023
    • 27th November 2023
    • 8th September 2023
    • 4th September 2023
    • 26th August 2023
    • 21st August 2023
    • 19th July 2023
    • 23rd May 2023
    • 5th May 2023
    • 28th April 2023
    • 19th April 2023
    • 15th April 2023
    • 10th April 2023
    • 30th March 2023
Powered by GitBook
On this page
  1. SQL Command Reference
  2. Date-Time Functions

Extraction Functions

Retrieve specific components from dates, times, and strings.

This section contains extraction functions that extract unit from an input expression. The table below contains the supported units for the given extraction functions.

Unit
Description

YEAR

extracts year

QUARTER

extracts quarter

MONTH

extracts month

WEEK

extracts week of the year

DAY

extracts day

DOY

extract the day of the year

DOW

extract ISO day of the week (ranges from 1 (Monday) to 7 (Sunday)

HOUR

extracts hour

MINUTE

extracts minute

SECOND

extracts second

EPOCH

extracts epoch time

EXTRACT( unit FROM <datetime expr> )

Returns the value of specified unit from the given date-time expression.

> select extract(MINUTE FROM cast('2022-01-02 12:27:11' as timestamp))
27

DATEPART( unit, <expr> )

Returns the specified unit of the given date/timestamp expression.

> select current_date, datepart('day', current_date) as day_val;
----------------------------------------
| current_date        |day_val         |
----------------------------------------
| 2023-01-06 00:00:00 |6               |
----------------------------------------

WEEK( <date_or_timestamp_expr> )

Returns the week number of the year.

> select week(FROM_UNIXTIME_WITHUNIT(1673263327000, 'milliseconds'))
2

YEAR( <date_or_timestamp_expr> )

Returns the year for a date or timestamp.

> select week(FROM_UNIXTIME_WITHUNIT(1673263327000, 'milliseconds'))
2

MONTH( <date_or_timestamp_expr> )

Returns the month for a date or timestamp.

> select month(date('2002-11-14'));
11

DAYS( <date_or_timestamp_expr> )

Returns the day of the month for a date or timestamp.

> select days(to_timestamp('2023-04-18 10:30:00'));
18
> select days(to_date('2023-04-12'));
12

LAST_DAY( <date_or_timestamp_expr> )

Return the last day of the month for a date or timestamp.

> select last_day(cast('2022-01-11' as date));
2022-01-31

DAYNAME( <date_or_timestamp_expr> )

Returns the three-letter day-of-week name for a date or timestamp.

> select dayname(cast('2024-03-09' as date))
Sat
> select dayname(cast('2024-03-11' as timestamp))
Mon

HOUR( <date_or_timestamp_expr> )

Returns the hour of the day from timestamp. The value ranges from 0 to 23.

> select hour(to_timestamp('2023-04-18 10:30:00'));
10

MINUTE( <date_or_timestamp_expr> )

Returns the minute of the hour from timestamp. The value ranges from 0 to 59.

> select minute(to_timestamp('2023-04-18 10:30:00'));
30

SECOND( <date_or_timestamp_expr> )

Returns the second of the minute from timestamp. The value ranges from 0 to 59.

> select second(to_timestamp('2023-04-18 10:30:45'));
45

DAYOFWEEKISO( <date_or_timestamp_expr> )

Day (number) of the week uses ISO semantics 1 to 7

> select DAYOFWEEKISO(tstamp) AS "DAYOFWEEKISO" from ( SELECT '2016-01-02T23:39:20.123-07:00'::TIMESTAMP AS tstamp)
6

WEEKOFYEAR( <date_or_timestamp_expr> )

Week (number) of the year 1 to 53.

> SELECT WEEKOFYEAR(tstamp) AS "WEEK OF YEAR" FROM (SELECT  '2016-01-02T23:39:20.123-07:00'::TIMESTAMP AS tstamp)
53

WEEKISO( <date_or_timestamp_expr> )

WEEKISO is the same as WEEKOFYEAR, except uses ISO semantics 1 to 53.

> SELECT WEEKISO(tstamp) AS "WEEK ISO" FROM (SELECT  '2016-01-02T23:39:20.123-07:00'::TIMESTAMP AS tstamp)
53
PreviousAddition and Subtraction FunctionsNextFormat Functions

Last updated 9 months ago