LogoLogo
BlogTwitterDiscordTelegramSignup/Login
  • Getting Started
    • Welcome to Spice.ai Cloud
    • Getting Started
      • Sign in with GitHub
      • Create a Spice app
      • Add a Dataset and query data
      • Add AI Model and chat with your data
      • Next Steps
    • FAQ
  • Features
    • Federated SQL Query
    • Data Acceleration
      • In-Memory Arrow Data Accelerator
      • DuckDB Data Accelerator
      • PostgreSQL Data Accelerator
      • SQLite Data Accelerator
    • Search & Retrieval
    • AI Gateway
    • Semantic Models
    • ML Models
    • Observability
      • Task History
      • Zipkin
  • Building Blocks
    • Data Connectors
      • ABFS
      • ClickHouse
      • Databricks
      • Delta Lake
      • Dremio
      • DuckDB
      • DynamoDB
      • FlightSQL
      • FTP
      • GitHub
      • GraphQL
      • HTTPS
      • LocalPod
      • Memory
      • MSSQL
      • MySQL
      • ODBC
      • Postgres
      • S3
      • SharePoint
      • Snowflake
      • Spark
      • SpiceAI
    • Model Providers
      • Anthropic
      • Azure
      • Hugging Face
      • OpenAI
      • Perplexity
      • SpiceAI
      • XAI
  • API
    • SQL Query API
      • HTTP API
      • Apache Arrow Flight API
    • OpenAI API
    • Health API
  • Portal
    • Playground
      • SQL Query
      • AI Chat
    • Organizations
    • Apps
      • API keys
      • Secrets
      • Connect GitHub
      • Transfer
    • Public Apps
    • App Spicepod
      • Spicepod Configuration
      • Deployments
      • Spice Runtime Versions
    • Monitoring
    • Profile
      • Personal Access Tokens
  • Use-Cases
    • Agentic AI Apps
    • Database CDN
    • Data Lakehouse
    • Enterprise Search
    • Enterprise RAG
  • SDKs
    • Python SDK
      • Streaming
    • Node.js SDK
      • Streaming
      • API Reference
    • Go SDK
    • Rust SDK
    • Dotnet SDK
    • Java SDK
  • Integrations
    • GitHub Copilot
    • Grafana
  • REFERENCE
    • Core Concepts
      • Duration Literals
    • SQL Reference
      • Data Types
      • SQL Functions
        • Aggregate
          • APPROX_COUNT_DISTINCT
          • AVG
          • BIT_AND
          • BIT_OR
          • CORR
          • COUNT
          • COVAR_POP
          • COVAR_SAMP
          • HLL
          • LISTAGG
          • MAX
          • MIN
          • NDV
          • STDDEV
          • STDDEV_POP
          • STDDEV_SAMP
          • SUM
          • VAR_POP
          • VAR_SAMP
        • Binary
          • BASE64
          • BIT_LENGTH
          • FROM_HEX
          • HEX
          • TO_HEX
          • UNBASE64
          • UNHEX
        • Bitwise
          • BIT_AND
          • BIT_OR
          • LSHIFT
          • RSHIFT
          • XOR
        • Boolean
          • IS [NOT] DISTINCT FROM
          • ISFALSE
          • IS [NOT] NULL
          • ISNUMERIC
          • ISTRUE
          • IS_MEMBER
        • Conditional
          • BOOL_AND
          • BOOL_OR
          • CASE
          • COALESCE
          • GREATEST
          • LEAST
          • NULLIF
        • Conversion
          • BINARY_STRING
          • CAST
          • CONVERT_FROM
          • CONVERT_REPLACEUTF8
          • CONVERT_TIMEZONE
          • CONVERT_TO
          • FLATTEN
          • FROM_HEX
          • HASH
          • HEX
          • TOASCII
          • TO_CHAR
          • TO_DATE
          • TO_HEX
          • TO_NUMBER
          • TO_TIME
          • TO_TIMESTAMP
          • UNHEX
        • Cryptography
          • AES_DECRYPT
          • AES_ENCRYPT
          • MD5
          • SHA
          • SHA1
          • SHA256
          • SHA512
        • Data Generation
          • RANDOM
        • Datatype
          • IS_BIGINT
          • IS_DATE
          • IS_INT
          • IS_VARCHAR
          • SIZE
          • TYPEOF
        • Date/Time
          • CONVERT_TIMEZONE
          • CURRENT_DATE
          • CURRENT_DATE_UTC
          • CURRENT_TIME
          • CURRENT_TIMESTAMP
          • DATEDIFF
          • DATE_ADD
          • DATE_DIFF
          • DATE_PART
          • DATE_SUB
          • DATE_TRUNC
          • DAY
          • DAYOFMONTH
          • DAYOFWEEK
          • DAYOFYEAR
          • EXTRACT
          • HOUR
          • LAST_DAY
          • MINUTE
          • MONTH
          • MONTHS_BETWEEN
          • NEXT_DAY
          • QUARTER
          • SECOND
          • TIMESTAMPADD
          • TIMESTAMPDIFF
          • TO_DATE
          • TO_TIME
          • TO_TIMESTAMP
          • UNIX_TIMESTAMP
          • WEEK
          • WEEKOFYEAR
          • YEAR
        • Math
          • ABS
          • ACOS
          • ASIN
          • ATAN
          • CBRT
          • CEILING
          • COS
          • COSH
          • COT
          • DEGREES
          • E
          • EXP
          • FLOOR
          • LOG
          • LOG10
          • MOD
          • PI
          • POWER
          • RADIANS
          • ROUND
          • SIGN
          • SIN
          • SINH
          • SQRT
          • STDDEV
          • STDDEV_POP
          • STDDEV_SAMP
          • TAN
          • TANH
          • TRUNCATE
        • Percentile
          • MEDIAN
          • PERCENTILE_CONT
          • PERCENTILE_DISC
        • Regular Expressions
          • REGEXP_EXTRACT
          • REGEXP_LIKE
          • REGEXP_MATCHES
          • REGEXP_REPLACE
          • REGEXP_SPLIT
        • Semistructured Data
          • ARRAY_CONTAINS
          • MAP_KEYS
          • MAP_VALUES
        • String
          • ASCII
          • BASE64
          • BTRIM
          • CHARACTER_LENGTH
          • CHAR_LENGTH
          • CHR
          • COL_LIKE
          • CONCAT
          • CONCAT_WS
          • ENDS_WITH
          • FROM_HEX
          • HEX
          • ILIKE
          • INITCAP
          • INSTR
          • IS_UTF8
          • LCASE
          • LEFT
          • LENGTH
          • LEVENSHTEIN
          • LIKE
          • LOCATE
          • LOWER
          • LPAD
          • LTRIM
          • MASK
          • MASK_FIRST_N
          • MASK_HASH
          • MASK_LAST_N
          • MASK_SHOW_FIRST_N
          • MASK_SHOW_LAST_N
          • OCTET_LENGTH
          • POSITION
          • QUOTE
          • REGEXP_EXTRACT
          • REGEXP_LIKE
          • REGEXP_MATCHES
          • REGEXP_REPLACE
          • REGEXP_SPLIT
          • REPEAT
          • REPEATSTR
          • REPLACE
          • REVERSE
          • RIGHT
          • RPAD
          • RTRIM
          • SIMILAR_TO
          • SOUNDEX
          • SPLIT_PART
          • STARTS_WITH
          • STRPOS
          • SUBSTRING
          • SUBSTRING_INDEX
          • TOASCII
          • TO_HEX
          • TRANSLATE
          • TRIM
          • UCASE
          • UNBASE64
          • UNHEX
          • UPPER
        • Window
          • COUNT
          • COVAR_POP
          • COVAR_SAMP
          • CUME_DIST
          • DENSE_RANK
          • FIRST_VALUE
          • HLL
          • LAG
          • LEAD
          • MAX
          • MIN
          • NDV
          • NTILE
          • PERCENT_RANK
          • RANK
          • ROW_NUMBER
          • SUM
          • VAR_POP
          • VAR_SAMP
      • SQL Commands
        • SELECT
        • USE
        • SHOW
        • DESCRIBE
        • WITH
    • Release Notes
  • Pricing
    • Paid Plans
    • Community Plan
  • Support
    • Support
  • Security
    • Security at Spice AI
    • Report a vulnerability
  • Legal
    • Privacy Policy
    • Website Terms of Use
    • Terms of Service
    • End User License Agreement
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. REFERENCE
  2. SQL Reference
  3. SQL Functions

Date/Time

Function Name
Description

Convert timestamp to the specified timezone.

Returns the current date of the system.

Returns the current date of the system based on the UTC timezone.

Returns the current time for the system.

Returns the current timestamp for the system in UTC time only.

Compares two dates or timestamps and returns the difference in days.

Returns the sum of two expressions of time as another expression of time.

Returns the difference between two expressions of time as another expression of time.

Return subfields such as year or hour from date or timestamp values.

Returns the difference of two expressions of time as another expression of time.

Truncates the date or timestamp to the indicated precision.

Returns the day of month of the date or timestamp.

Returns the day of month of the date or timestamp.

Returns the day of the week (from 1 to 7) of the date or timestamp.

Returns the day of the year (from 1 to 366) of the date or timestamp.

Extracts the specified date or time part from the date or timestamp.

Extracts the hour number (from 0 to 23) for a given time or timestamp.

Returns the last day of the month for the specified date or timestamp.

Extracts the minute number (from 0 to 59) for a given time or timestamp.

Extracts the month number (from 1 to 12) for a given date or timestamp.

Returns the number of months between two date or timestamp values.

Returns the date or timestamp of the first specified day of week that occurs after the input date.

Extracts the quarter number (from 1 to 4) for a given date or timestamp.

Extracts the second number (from 0 to 59) for a given date or timestamp.

Add (or subtract) an interval of time from a date/timestamp value or column.

Return the amount of time between two date or timestamp values

Converts the input expressions to the corresponding date.

Converts the input expressions to the corresponding time.

Converts the input expressions to the corresponding timestamp.

Returns the Unix epoch time representation of an ISO 8601 timestamp.

Extracts the week number (from 0 to 53) for a given date or timestamp.

Returns the week of year of the date or timestamp.

Extracts the year for a given date or timestamp.

Date/Time Formatting

Format Element
Description
Example

AD/BC

Era indicator

AD, BC

AMPM

Meridian indicator

AM, PM

CC

Century indicator (0-99)

19

WW

Week of year (0-52)

4, 43

D

Day of week (1-7)

6

DY

Abbreviated day name of week

Tue, Fri

DAY

Full day name of week

Tuesday, Friday

YYYY

Four digits of year

1996

YY

Last two digits of year

96

DDD

Day of year (1-366)

5, 245

MM

Month (1-12)

8

MON

Abbreviated month name

Mar, Oct

MONTH

Full month name

March, October

DD

Day of month (1-31)

24

HH/HH12

Hour of day (1-12)

4

HH24

Hour of day (0-23)

21

MI

Minutes (0-59)

22

SS

Seconds (0-59)

54

FFF

Milliseconds

121

TZD

Timezone abbreviation

UTC, PST

TZO

Timezone offset

+02:00, -0800

Only the following characters are allowed in a format pattern: - / , . ; :. If you need to let a value pass through to the output unmodified you can surround it with " (for example "T").

If you convert a date to text, numeric values are zero padded for you. For example, MM returns 04 for April.

Last updated 2 years ago

Was this helpful?

CONVERT_TIMEZONE
CURRENT_DATE
CURRENT_DATE_UTC
CURRENT_TIME
CURRENT_TIMESTAMP
DATEDIFF
DATE_ADD
DATE_DIFF
DATE_PART
DATE_SUB
DATE_TRUNC
DAY
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
EXTRACT
HOUR
LAST_DAY
MINUTE
MONTH
MONTHS_BETWEEN
NEXT_DAY
QUARTER
SECOND
TIMESTAMPADD
TIMESTAMPDIFF
TO_DATE
TO_TIME
TO_TIMESTAMP
UNIX_TIMESTAMP
WEEK
WEEKOFYEAR
YEAR