

 Amazon Redshift will no longer support the creation of new Python UDFs starting Patch 198. Existing Python UDFs will continue to function until June 30, 2026. For more information, see the [ blog post ](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

# Date and time functions
<a name="Date_functions_header"></a>

In this section, you can find information about the date and time scalar functions that Amazon Redshift supports.

**Topics**
+ [Summary of date and time functions](#date-functions-summary)
+ [Date and time functions in transactions](#date-functions-transactions)
+ [Deprecated leader node-only functions](#date-functions-deprecated)
+ [\+ (Concatenation) operator](r_DATE-CONCATENATE_function.md)
+ [ADD\_MONTHS function](r_ADD_MONTHS.md)
+ [AT TIME ZONE function](r_AT_TIME_ZONE.md)
+ [CONVERT\_TIMEZONE function](CONVERT_TIMEZONE.md)
+ [CURRENT\_DATE function](r_CURRENT_DATE_function.md)
+ [DATE\_CMP function](r_DATE_CMP.md)
+ [DATE\_CMP\_TIMESTAMP function](r_DATE_CMP_TIMESTAMP.md)
+ [DATE\_CMP\_TIMESTAMPTZ function](r_DATE_CMP_TIMESTAMPTZ.md)
+ [DATEADD function](r_DATEADD_function.md)
+ [DATEDIFF function](r_DATEDIFF_function.md)
+ [DATE\_PART function](r_DATE_PART_function.md)
+ [DATE\_PART\_YEAR function](r_DATE_PART_YEAR.md)
+ [DATE\_TRUNC function](r_DATE_TRUNC.md)
+ [EXTRACT function](r_EXTRACT_function.md)
+ [GETDATE function](r_GETDATE.md)
+ [INTERVAL\_CMP function](r_INTERVAL_CMP.md)
+ [LAST\_DAY function](r_LAST_DAY.md)
+ [MONTHS\_BETWEEN function](r_MONTHS_BETWEEN_function.md)
+ [NEXT\_DAY function](r_NEXT_DAY.md)
+ [SYSDATE function](r_SYSDATE.md)
+ [TIMEOFDAY function](r_TIMEOFDAY_function.md)
+ [TIMESTAMP\_CMP function](r_TIMESTAMP_CMP.md)
+ [TIMESTAMP\_CMP\_DATE function](r_TIMESTAMP_CMP_DATE.md)
+ [TIMESTAMP\_CMP\_TIMESTAMPTZ function](r_TIMESTAMP_CMP_TIMESTAMPTZ.md)
+ [TIMESTAMPTZ\_CMP function](r_TIMESTAMPTZ_CMP.md)
+ [TIMESTAMPTZ\_CMP\_DATE function](r_TIMESTAMPTZ_CMP_DATE.md)
+ [TIMESTAMPTZ\_CMP\_TIMESTAMP function](r_TIMESTAMPTZ_CMP_TIMESTAMP.md)
+ [TIMEZONE function](r_TIMEZONE.md)
+ [TO\_TIMESTAMP function](r_TO_TIMESTAMP.md)
+ [TRUNC function](r_TRUNC_date.md)
+ [Date parts for date or timestamp functions](r_Dateparts_for_datetime_functions.md)

## Summary of date and time functions
<a name="date-functions-summary"></a>


| Function | Syntax | Returns | 
| --- | --- | --- | 
| [\+ (Concatenation) operator](r_DATE-CONCATENATE_function.md)Concatenates a date to a time on either side of the \+ symbol and returns a TIMESTAMP or TIMESTAMPTZ.  | date \+ time | TIMESTAMP or TIMESTAMPZ | 
| [ADD\_MONTHS](r_ADD_MONTHS.md)Adds the specified number of months to a date or timestamp. |  ADD\_MONTHS ({date\|timestamp}, integer) | TIMESTAMP | 
| [AT TIME ZONE](r_AT_TIME_ZONE.md)Specifies which time zone to use with a TIMESTAMP or TIMESTAMPTZ expression. |  AT TIME ZONE 'timezone' | TIMESTAMP or TIMESTAMPZ | 
| [CONVERT\_TIMEZONE](CONVERT_TIMEZONE.md)Converts a timestamp from one time zone to another. | CONVERT\_TIMEZONE (['timezone',] 'timezone', timestamp) | TIMESTAMP | 
| [CURRENT\_DATE](r_CURRENT_DATE_function.md)Returns a date in the current session time zone (UTC by default) for the start of the current transaction. | CURRENT\_DATE | DATE | 
| [DATE\_CMP](r_DATE_CMP.md)Compares two dates and returns `0` if the dates are identical, `1` if *date1* is greater, and `-1` if *date2* is greater. | DATE\_CMP (date1, date2) | INTEGER | 
| [DATE\_CMP\_TIMESTAMP](r_DATE_CMP_TIMESTAMP.md)Compares a date to a time and returns `0` if the values are identical, `1` if *date* is greater and `-1` if *timestamp* is greater. | DATE\_CMP\_TIMESTAMP (date, timestamp) | INTEGER | 
| [DATE\_CMP\_TIMESTAMPTZ](r_DATE_CMP_TIMESTAMPTZ.md)Compares a date and a timestamp with time zone and returns `0` if the values are identical, `1` if *date* is greater and `-1` if *timestamptz* is greater. | DATE\_CMP\_TIMESTAMPTZ (date, timestamptz) | INTEGER | 
| [DATE\_PART\_YEAR](r_DATE_PART_YEAR.md)Extracts the year from a date. | DATE\_PART\_YEAR (date) | INTEGER | 
| [DATEADD](r_DATEADD_function.md)Increments a date or time by a specified interval. | DATEADD (datepart, interval, {date\|time\|timetz\|timestamp}) | TIMESTAMP or TIME or TIMETZ | 
| [DATEDIFF](r_DATEDIFF_function.md)Returns the difference between two dates or times for a given date part, such as a day or month. | DATEDIFF (datepart, {date\|time\|timetz\|timestamp}, {date\|time\|timetz\|timestamp}) | BIGINT | 
| [DATE\_PART](r_DATE_PART_function.md)Extracts a date part value from a date or time. | DATE\_PART (datepart, {date\|timestamp}) | DOUBLE | 
| [DATE\_TRUNC](r_DATE_TRUNC.md)Truncates a timestamp based on a date part. | DATE\_TRUNC ('datepart', timestamp) | TIMESTAMP | 
| [EXTRACT](r_EXTRACT_function.md)Extracts a date or time part from a timestamp, timestamptz, time, or timetz. | EXTRACT (datepart FROM source) | INTEGER or DOUBLE | 
| [GETDATE](r_GETDATE.md)Returns the current date and time in the current session time zone (UTC by default). The parentheses are required. | GETDATE() | TIMESTAMP | 
| [INTERVAL\_CMP](r_INTERVAL_CMP.md)Compares two intervals and returns `0` if the intervals are equal, `1` if *interval1* is greater, and `-1` if *interval2* is greater. | INTERVAL\_CMP (interval1, interval2) | INTEGER | 
| [LAST\_DAY](r_LAST_DAY.md)Returns the date of the last day of the month that contains *date*. | LAST\_DAY(date) | DATE | 
| [MONTHS\_BETWEEN](r_MONTHS_BETWEEN_function.md)Returns the number of months between two dates. | MONTHS\_BETWEEN (date, date) | FLOAT8 | 
| [NEXT\_DAY](r_NEXT_DAY.md)Returns the date of the first instance of *day* that is later than *date*. | NEXT\_DAY (date, day) | DATE | 
| [SYSDATE](r_SYSDATE.md)Returns the date and time in UTC for the start of the current transaction. | SYSDATE | TIMESTAMP | 
| [TIMEOFDAY](r_TIMEOFDAY_function.md)Returns the current weekday, date, and time in the current session time zone (UTC by default) as a string value.  | TIMEOFDAY() | VARCHAR | 
| [TIMESTAMP\_CMP](r_TIMESTAMP_CMP.md)Compares two timestamps and returns `0` if the timestamps are equal, `1` if *timestamp1* is greater, and `-1` if *timestamp2* is greater. | TIMESTAMP\_CMP (timestamp1, timestamp2) | INTEGER | 
| [TIMESTAMP\_CMP\_DATE](r_TIMESTAMP_CMP_DATE.md)Compares a timestamp to a date and returns `0` if the values are identical, `1` if *timestamp* is greater, and `-1` if *date* is greater. | TIMESTAMP\_CMP\_DATE (timestamp, date) | INTEGER | 
| [TIMESTAMP\_CMP\_TIMESTAMPTZ](r_TIMESTAMP_CMP_TIMESTAMPTZ.md)Compares a timestamp with a timestamp with time zone and returns `0` if the values are equal, `1` if *timestamp* is greater, and `-1` if *timestamptz* is greater. | TIMESTAMP\_CMP\_TIMESTAMPTZ (timestamp, timestamptz) | INTEGER | 
| [TIMESTAMPTZ\_CMP](r_TIMESTAMPTZ_CMP.md)Compares two timestamp with time zone values and returns `0` if the values are equal, `1` if *timestamptz1* is greater, and `-1` if *timestamptz2* is greater. | TIMESTAMPTZ\_CMP (timestamptz1, timestamptz2) | INTEGER | 
| [TIMESTAMPTZ\_CMP\_DATE](r_TIMESTAMPTZ_CMP_DATE.md)Compares the value of a timestamp with time zone and a date and returns `0` if the values are equal, `1` if *timestamptz* is greater, and `-1` if *date* is greater. | TIMESTAMPTZ\_CMP\_DATE (timestamptz, date) | INTEGER | 
| [TIMESTAMPTZ\_CMP\_TIMESTAMP](r_TIMESTAMPTZ_CMP_TIMESTAMP.md)Compares a timestamp with time zone with a timestamp and returns `0` if the values are equal, `1` if *timestamptz* is greater, and `-1` if *timestamp* is greater. | TIMESTAMPTZ\_CMP\_TIMESTAMP (timestamptz, timestamp) | INTEGER | 
| [TIMEZONE](r_TIMEZONE.md)Returns a timestamp for the specified time zone and timestamp value. | TIMEZONE ('timezone' { timestamp \| timestamptz ) | TIMESTAMP or TIMESTAMPTZ | 
| [TO\_TIMESTAMP](r_TO_TIMESTAMP.md)Returns a timestamp with time zone for the specified timestamp and time zone format. | TO\_TIMESTAMP ('timestamp', 'format') | TIMESTAMPTZ | 
| [TRUNC](r_TRUNC_date.md)Truncates a timestamp and returns a date. | TRUNC(timestamp) | DATE | 

**Note**  
Leap seconds are not considered in elapsed-time calculations.

## Date and time functions in transactions
<a name="date-functions-transactions"></a>

When you run the following functions within a transaction block (BEGIN … END), the function returns the start date or time of the current transaction, not the start of the current statement.
+ SYSDATE
+ TIMESTAMP
+ CURRENT\_DATE

The following functions always return the start date or time of the current statement, even when they are within a transaction block.
+ GETDATE
+ TIMEOFDAY

## Deprecated leader node-only functions
<a name="date-functions-deprecated"></a>

The following date functions are deprecated because they run only on the leader node. For more information, see [Leader node–only functions](c_SQL_functions_leader_node_only.md).
+ AGE. Use [DATEDIFF function](r_DATEDIFF_function.md) instead.
+ CURRENT\_TIME. Use [GETDATE function](r_GETDATE.md) or [SYSDATE](r_SYSDATE.md) instead. 
+ CURRENT\_TIMESTAMP. Use [GETDATE function](r_GETDATE.md) or [SYSDATE](r_SYSDATE.md) instead.
+ LOCALTIME. Use [GETDATE function](r_GETDATE.md) or [SYSDATE](r_SYSDATE.md) instead.
+ LOCALTIMESTAMP. Use [GETDATE function](r_GETDATE.md) or [SYSDATE](r_SYSDATE.md) instead.
+ ISFINITE 
+ NOW. Use [GETDATE function](r_GETDATE.md) or [SYSDATE](r_SYSDATE.md) instead. If you use the NOW function within a materialized view, it sets to the timestamp of the creation of the materialized view, instead of the current timestamp. 