select now()::date
select date_part('day',now()::timestamp - '2016-1-11'::timestamp)
下表列出了基本算术操作符的行为:
运算符 | 实例 | 结果 | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
+ | date '2001-09-28' + integer '7' | date '2001-10-05' | ||||||||||||||||||||||||
date '2001-09-28' + interval '1 hour' | timestamp '2001-09-28 01:00:00' | |||||||||||||||||||||||||
date '2001-09-28' + time '03:00' | timestamp '2001-09-28 03:00:00' | |||||||||||||||||||||||||
interval '1 day' + interval '1 hour' | interval '1 day 01:00:00' | |||||||||||||||||||||||||
timestamp '2001-09-28 01:00' + interval '23 hours' | timestamp '2001-09-29 00:00:00' | |||||||||||||||||||||||||
time '01:00' + interval '3 hours' | time '04:00:00' | |||||||||||||||||||||||||
- | - interval '23 hours' | interval '-23:00:00' | ||||||||||||||||||||||||
date '2001-10-01' - date '2001-09-28' | integer '3' (days) | |||||||||||||||||||||||||
date '2001-10-01' - integer '7' | date '2001-09-24' | |||||||||||||||||||||||||
date '2001-09-28' - interval '1 hour' | timestamp '2001-09-27 23:00:00' | |||||||||||||||||||||||||
time '05:00' - time '03:00' | interval '02:00:00' | |||||||||||||||||||||||||
time '05:00' - interval '2 hours' | time '03:00:00' | |||||||||||||||||||||||||
timestamp '2001-09-28 23:00' - interval '23 hours' | timestamp '2001-09-28 00:00:00' | |||||||||||||||||||||||||
interval '1 day' - interval '1 hour' | interval '1 day -01:00:00' | |||||||||||||||||||||||||
timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00' | interval '1 day 15:00:00' | |||||||||||||||||||||||||
* | 900 * interval '1 second' | interval '00:15:00' | ||||||||||||||||||||||||
21 * interval '1 day' | interval '21 days' | |||||||||||||||||||||||||
double precision '3.5' * interval '1 hour' | interval '03:30:00' | |||||||||||||||||||||||||
/ | interval '1 hour' / double precision '1.5' | interval '00:40:00' |
描述 | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AGE() | Subtract arguments | |||||||||||||||||||||||||
CURRENT DATE/TIME() | Current date and time | |||||||||||||||||||||||||
DATE_PART() | Get subfield (equivalent to extract) | |||||||||||||||||||||||||
EXTRACT() | Get subfield | |||||||||||||||||||||||||
ISFINITE() | Test for finite date,time and interval (not +/-infinity) | |||||||||||||||||||||||||
JUSTIFY | Adjust interval |
When invoked with the TIMESTAMP form of the second argument,AGE() subtract arguments,producing a "symbolic" result that uses years and months and is of type INTERVAL. | ||||||||||||||||||||||||||
AGE(timestamp) | When invoked with only the TIMESTAMP as argument,AGE() subtracts from the current_date (at midnight). | Delivers current date. | ||||||||||||||||||||||||
CURRENT_TIME | Deliver values with time zone. | |||||||||||||||||||||||||
CURRENT_TIMESTAMP | CURRENT_TIME(precision) | Optionally takes a precision parameter,which causes the result to be rounded to that many fractional digits in the seconds field. | ||||||||||||||||||||||||
CURRENT_TIMESTAMP(precision) | LOCALTIME | Deliver values without time zone. | ||||||||||||||||||||||||
LOCALTIMESTAMP | LOCALTIME(precision) | Optionally take a precision parameter,214); padding:5px; margin:0px"> LOCALTIMESTAMP(precision) | 502_155@
例子使用的功能表所示: =# SELECT CURRENT_TIME; timetz -------------------- 08:0134.656+0530 (1 row) testdb=# SELECT CURRENT_DATE; date ------------ 2013-05 =# SELECT CURRENT_TIMESTAMP; now ------------------------------- 05 45.3752); timestamptz ------------------------------ 50.89=# SELECT LOCALTIMESTAMP; timestamp ------------------------ 55.75 ) Postgresql还提供了当前语句的开始时间,以及当前的实际时间的瞬间,该函数被调用的函数返回。这些函数包括:
|