Unsupported versions: 7.0
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

Date/Time Functions

The date/time functions provide a powerful set of tools for manipulating various date/time types.

Table 5-6. Date/Time Functions

Function Returns Description Example
abstime(timestamp) abstime convert to abstime abstime(timestamp 'now')
age(timestamp) interval preserve months and years age(timestamp '1957-06-13')
age(timestamp,timestamp) interval preserve months and years age('now', timestamp '1957-06-13')
date_part(text,timestamp) float8 portion of date date_part('dow',timestamp 'now')
date_part(text,interval) float8 portion of time date_part('hour',interval '4 hrs 3 mins')
date_trunc(text,timestamp) timestamp truncate date date_trunc('month',abstime 'now')
interval(reltime) interval convert to interval interval(reltime '4 hours')
isfinite(timestamp) bool a finite time? isfinite(timestamp 'now')
isfinite(interval) bool a finite time? isfinite(interval '4 hrs')
reltime(interval) reltime convert to reltime reltime(interval '4 hrs')
timestamp(date) timestamp convert to timestamp timestamp(date 'today')
timestamp(date,time) timestamp convert to timestamp timestamp(timestamp '1998-02-24',time '23:07');
to_char(timestamp,text) text convert to string to_char(timestamp '1998-02-24','DD');

For the date_part and date_trunc functions, arguments can be `year', `month', `day', `hour', `minute', and `second', as well as the more specialized quantities `decade', `century', `millennium', `millisecond', and `microsecond'. date_part allows `dow' to return day of week, 'week' to return the ISO-defined week of year, and `epoch' to return seconds since 1970 (for timestamp) or 'epoch' to return total elapsed seconds (for interval).