| Function | Description and Comments | Example |
|---|---|---|
CURRENT_DATE | Return the date in which the current transaction started Returns DATE | SELECT CURRENT_DATE;=> 2012-03-26 |
CURRENT_TIME | Return current time (start of current transaction) Returns TIME | SELECT CURRENT_TIME;=> 11:31:46.903633 |
CURRENT_TIMESTAMP | Returns current timestamp (start of current transaction) Returns TIMESTAMPSee notes | SELECT CURRENT_TIMESTAMP;=> 2012-03-26 11:31:46.903633 |
NOW() | Returns current date and time (start of current transaction) Returns TIMESTAMPSee notes | SELECT NOW();=> 2012-03-26 11:31:46.903633 |
EXTRACT(unit FROM TIMESTAMP) | Extracts the specified unit (date or time part) from a date, time, or timestamp Returns DECIMALSee notes | SELECT EXTRACT(YEAR FROM TIMESTAMP '2012-03-26 11:31:46.903633');=> 2012 SELECT EXTRACT('day' FROM DATE '2012-03-26');=> 26 |
DATE_PART(unit, TIMESTAMP) | Similar to EXTRACT()Returns DECIMALSee notes | SELECT DATE_PART('day', TIMESTAMP '2012-03-26 11:31:46.903633');=> 26 SELECT DATE_PART('minute', TIME '11:31:46.903633');=> 31 |
-
NOW()andCURRENT_TIMESTAMP: When using those functions as part of anINSERT/UPDATEcommand, the returned value is converted into the column data type it is writing to. When writing intoTIMEdata type, only the time is written, when writing intoDATEdata type, only the date is written, and when writing toTIMESTAMPdata type, the whole timestamp is written. Note thatNOW()andCURRENT_TIMESTAMPrefer to the time the transaction starts, and not to each statement time inside the transaction -
DATE_PART()andEXTRACT()provide similar functionality and accept the same set of units. However,DATE_PARTrequires the unit argument to be passed as a string (e.g. ‘YEAR”, ‘day’), whileEXTRACT()also accepts these units as keywords. The following units are supported:
| Time Units | Date Units |
|---|---|
MICROSECONDS | DAY |
MILLISECONDS | WEEK |
SECOND | MONTH |
MINUTE | QUARTER |
HOUR | YEAR |
DECADE | |
CENTURY | |
MILLENNIUM |
TIMESTAMP object, both the Date and Time units are supported.