Skip to main content

Basic Date and Time Functions

ADD_MONTHS

Adds the specified number of months to the date. Equivalent to using a date and adding a MONTH(value). Syntax
SQL
Example
SQL
Output: 2023-01-15

CENTURY

Returns the number of centuries. Syntax
SQL
Example In this example, the current date is 2023-01-03.
SQL
Output: 21

CURDATE

Alias for CURRENT_DATE.

CURRENT_DATE

Alias for CURDATE. Returns the current date in the format YYYY-MM-DD. Syntax
SQL
Example
SQL
Output: 2023-01-03

CURRENT_TIME

Returns the current time as a TIME value (e.g., hh:mm:ss.mm). Syntax
SQL
Example
SQL
Output: 19:40:04

CURRENT_TIMESTAMP

Alias for NOW. Returns the current date and time as a TIMESTAMP value (e.g., YYYY-MM-DD hh:mm:ss.mmm). Syntax
SQL
Example
SQL
Output: 2023-01-03 11:00:03.316674397

DATE_PART

Alias for EXTRACT.

DATE_TRUNC

Returns the date or timestamp entered, truncated to the specified precision. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-01-03 11:00:59.114058182.
SQL
Output: 2023-01-03 11:01:05.280975906 Example This example uses CURRENT_TIMESTAMP set to 2023-01-01 11:00:59.114058181.
SQL
Output: 2023-01-01 00:00:00.000000000 Example This example uses CURRENT_TIMESTAMP set to 2023-01-01 11:00:59.114058181.
SQL
Output: 2001-01-01 00:00:00.000000000

DAY

Alias for DAY_OF_MONTH.

DAY_OF_WEEK

Returns an integer, in the range of 1 to 7, that represents the day of the week. The value 1 is Sunday, and 7 is Saturday. Syntax
SQL
Example
SQL
Output: 3

DAY_OF_YEAR

Alias for DOY. Returns an integer in the range 1 to 366 that represents the day of the year. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-01-03 11:00:59.114058182.
SQL
Output: 3

DAY_OF_MONTH

Alias for DAY. Extracts the day-of-month portion of a timestamp or date as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-01-03 11:00:59.114058182.
SQL
Output: 3

DECADE

The decade is the year divided by 10. Syntax
SQL
Example This example uses CURRENT_DATE set to 2023-01-03.
SQL
Output: 202

DOW

Alias for DAY_OF_WEEK.

DOY

Alias for DAY_OF_YEAR.

EOMONTH

Returns the last day of the month using the specified timestamp or date. If you specify both arguments, this function returns the last day of the month for the resulting timestamp or date after the system adds the specified number of months to the first argument value. Syntax
SQL
Examples This example returns the last day of the month for the current timestamp.
SQL
Output: 2023-02-27 This example returns the last day of the month in November in 2022 by using the EOMONTH function to add one month to the last day of October in 2022.
SQL
Output: 2022-11-30

EPOCH

The number of seconds after 1970-01-01 00:00:00 UTC. Syntax
SQL
Example
SQL
Output: 1672743901

EXTRACT

Extract a component from a timestamp or date. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-01-03 11:00:59.114058182.
SQL
Output: 11.0

HOUR

Extracts the hour portion of a timestamp as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-01-03 11:00:59.114058182.
SQL
Output: 11

ISODOW

Extracts the day of the week based on ISO 8601, which ranges from Monday (1) to Sunday (7). Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-01-03 11:00:59.114058182.
SQL
Output: 2

ISDATE

Returns TRUE if the input argument can be successfully cast to a date, FALSE otherwise. Syntax
SQL
Example
SQL
Output: TRUE

MAKEDATETIME

Returns a timestamp consisting of the specified date and time. Syntax
SQL
Example
SQL
Output: 2022-11-02 01:24:58.000000000

MILLISECOND

Extracts the millisecond portion of a timestamp as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-22 13:59:25.286.
SQL
Output: 286

MINUTE

Extracts the minute portion of a timestamp or date as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-22 14:00:40.764.
SQL
Output: 0

MONTH_NAME

Returns the calendar name in English of the month for the specified date. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-22 13:59:25.286.
SQL
Output: February

MONTHS_BETWEEN

Returns the difference between the two dates or timestamps in months as a DOUBLE. The fractional months component is based on a 31-day month. If the two dates have the same day or are both the last day of the month, this function returns a whole number instead. Syntax
SQL
Example
SQL
Output: -11

MONTH

Extracts the month portion of a timestamp or date as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-22 13:59:25.286.
SQL
Output: 2

MSECS

The seconds field, including fractional parts. This is the same as EXTRACT(MILLISECONDS FROM time). Syntax
SQL
Example
SQL
Output: 37637.648

NANOS_TO_TIMESTAMP

Convert a number of nanoseconds into a timestamp equivalent to the duration after the epoch time, 1970-01-01 00:00:00 UTC. Syntax
SQL
Example
SQL
Output: 1969-12-31 16:00:00.010

NEXT_DAY

Returns the closest date after a specified date that lies on a specific day of the week. Syntax
SQL
Example
SQL
Output: 2023-03-04

NOW

Alias for CURRENT_TIMESTAMP.

QUARTER

Returns an integer between 1 and 4 representing the quarter of the year in which the specified date falls. Syntax
SQL
Example
SQL
Output: 1

ROUND

Returns the specified date or timestamp, rounded to the specified precision. The precision argument behaves like DATE_TRUNC. The function rounds up values to the specified precision. Syntax
SQL
Example
SQL
Output: 2023-02-08 09:00:00.000

SECOND

Extracts the seconds portion of a timestamp as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-28 13:17:30.243.
SQL
Output: 30

TIMESTAMP_TO_NANOS

Convert timestamp into nanoseconds after epoch as BIGINT. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-28 13:20:12.373.
SQL
Output: 1677619212373708904

TO_TIMESTAMP

For information on using the TO_TIMESTAMP conversion function, see the TO_TIMESTAMP page.

USECS

Returns the seconds part of a time value, including fractional parts, as an integer. Same as EXTRACT(MICROSECONDS FROM time). Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-28 13:32:17.438.
SQL
Output: 17438041

WEEK

Returns the ISO-8601 week number, as an integer, of the specified timestamp or date value. The week starts on Monday, and the first week of a year contains January 4 of that year. For details, see the ISO week date definition. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-28 13:37:37.128.
SQL
Output: 9

YEAR

Extracts the year portion of a timestamp or date as an integer. Syntax
SQL
Example This example uses CURRENT_TIMESTAMP set to 2023-02-28 13:37:37.128.
SQL
Output: 2023

Advanced Date and Time Functions

DATEADD

This function adds a specified number value (as a signed integer) to a specified datepart of an input date value, and then returns that modified value. The data type of the returned value for this function is dynamic. The return type depends on the argument supplied for date. If the value for date is a string literal date, DATEADD returns a datetime value. If another valid input data type is supplied for date, DATEADD returns the same data type. DATEADD raises an error if the string literal seconds scale exceeds three decimal place positions (.nnn) or if the string literal contains the time zone offset part. Syntax
SQL
DATEADD does not accept user-defined variable equivalents for the datepart arguments.
Examples This example shows each result from incrementing different datepart values by 1.
SQL
Output
Text
In this example, each statement increments datepart by a number large enough to increment the next higher unit of date or time.
SQL
Output
Text

DATEDIFF

This function returns an INT representing the difference between two date or time values, in a specified date or time unit. If only a time value is assigned to a date data type variable, DATEDIFF sets the value of the missing datepart to the default value: 1900-01-01. If only a date value is assigned to a variable of a time or date data type, DATEDIFF sets the value of the missing time part to the default value: 00:00:00. If either startdate or enddate have only a time part and the other only a datepart, DATEDIFF sets the missing time and datepart to the default values. If startdate and enddate have different date data types, and one has more time parts or fractional seconds precision than the other, DATEDIFF sets the missing parts of the other to 0. Syntax
SQL
For millisecond, the maximum difference between startdate and enddate is 24 days, 20 hours, 31 minutes, and 23.647 seconds.For second, the maximum difference is 68 years, 19 days, 3 hours, 14 minutes, and 7 seconds.
Each specific datepart name and abbreviations for that datepart name return the same value.
Example The example shows how DATEDIFF calculates the difference between the two values based on the various datepart values.
SQL
Output
Text
Time Zone Functions Formatting Functions
Last modified on May 20, 2026