Skip to main content

Date Functions

This section describes functions and operators for examining and manipulating date values.

Date Operators​

The table below shows the available mathematical operators for DATE types.

OperatorDescriptionExampleResult
+addition of days (integers)DATE '1992-03-22' + 51992-03-27
+addition of an INTERVALDATE '1992-03-22' + INTERVAL 5 DAY1992-03-27
+addition of a variable INTERVALSELECT DATE '1992-03-22' + INTERVAL 1 DAY * d.days FROM (VALUES (5), (11)) AS d(days)1992-03-27 1992-04-02
-subtraction of DATEsDATE '1992-03-27' - DATE '1992-03-22'5
-subtraction of an INTERVALDATE '1992-03-27' - INTERVAL 5 DAY'1992-03-22
-subtraction of a variable INTERVALSELECT DATE '1992-03-27' - INTERVAL 1 DAY * d.days FROM (VALUES (5), (11)) AS d(days)1992-03-22 1992-03-16

Adding to or subtracting from infinite values produces the same infinite value.

Date Functions​

The table below shows the available functions for DATE types. Dates can also be manipulated with the timestamp functions through type promotion.

FunctionDescriptionExampleResult
current_dateCurrent date (at start of current transaction)current_date2022-10-08
date_diff(part, startdate, enddate)The number of partition boundaries between the datesdate_diff('month', DATE '1992-09-15', DATE '1992-11-14')2
datediff(part, startdate, enddate)Alias of date_diff. The number of partition boundaries between the datesdatediff('month', DATE '1992-09-15', DATE '1992-11-14')2
date_part(part, date)Get the subfield (equivalent to extract)date_part('year', DATE '1992-09-20')1992
datepart(part, date)Alias of date_part. Get the subfield (equivalent to extract)datepart('year', DATE '1992-09-20')1992
date_sub(part, startdate, enddate)The number of complete partitions between the datesdate_sub('month', DATE '1992-09-15', DATE '1992-11-14')1
datesub(part, startdate, enddate)Alias of date_sub. The number of complete partitions between the datesdatesub('month', DATE '1992-09-15', DATE '1992-11-14')1
date_trunc(part, date)Truncate to specified precisiondate_trunc('month', DATE '1992-03-07')1992-03-01
datetrunc(part, date)Alias of date_trunc. Truncate to specified precisiondatetrunc('month', DATE '1992-03-07')1992-03-01
dayname(date)The (English) name of the weekdaydayname(DATE '1992-09-20')Sunday
isfinite(date)Returns true if the date is finite, false otherwiseisfinite(DATE '1992-03-07')true
isinf(date)Returns true if the date is infinite, false otherwiseisinf(DATE '-infinity')true
extract(part from date)Get subfield from a dateextract('year' FROM DATE '1992-09-20')1992
greatest(date, date)The later of two datesgreatest(DATE '1992-09-20', DATE '1992-03-07')1992-09-20
last_day(date)The last day of the corresponding month in the datelast_day(DATE '1992-09-20')1992-09-30
least(date, date)The earlier of two datesleast(DATE '1992-09-20', DATE '1992-03-07')1992-03-07
make_date(bigint, bigint, bigint)The date for the given partsmake_date(1992, 9, 20)1992-09-20
monthname(date)The (English) name of the monthmonthname(DATE '1992-09-20')September
strftime(date, format)Converts a date to a string according to the format stringstrftime(date '1992-01-01', '%a, %-d %B %Y')Wed, 1 January 1992
time_bucket(bucket_width, date[, origin])Truncate date by the specified interval bucket_width. Buckets are aligned relative to origin date. origin defaults to 2000-01-03 for buckets that don't include a month or year interval, and to 2000-01-01 for month and year buckets.time_bucket(INTERVAL '2 weeks', DATE '1992-04-20', DATE '1992-04-01')1992-04-15
time_bucket(bucket_width, date[, offset])Truncate date by the specified interval bucket_width. Buckets are offset by offset interval.time_bucket(INTERVAL '2 months', DATE '1992-04-20', INTERVAL '1 month')1992-04-01
today()Current date (start of current transaction)today()2022-10-08

There are also dedicated extraction functions to get the subfields.

Functions applied to infinite dates will either return the same infinite dates (e.g, greatest) or NULL (e.g., date_part) depending on what "makes sense". In general, if the function needs to examine the parts of the infinite date, the result will be NULL.