PostgreSQL 日期时间函数参考

本页整理了常用的 PostgreSQL 日期和时间相关的函数。

  1. age

    PostgreSQL age() 函数根据指定的生日返回指定日期或现在的年龄,返回格式为 x years x mons x days
  2. clock_timestamp

    PostgreSQL clock_timestamp() 函数返回此函数执行时的日期和时间。同一个语句中的两次执行 clock_timestamp() 的返回值可能不同。
  3. current_date

    PostgreSQL current_date 函数返回当前的系统日期,格式为 YYYY-MM-DD
  4. current_time

    PostgreSQL current_time 函数返回带有时区信息的系统时间,格式为 HH:MI:SS.ssssss{+|-}ZZ
  5. current_timestamp

    PostgreSQL current_timestamp() 函数返回当前的日期和时间(所属事务开始的时间)。
  6. date_bin

    PostgreSQL date_bin() 函数将指定的时间戳截断到最近的指定的时间间隔的开始。
  7. date_part

    PostgreSQL date_part() 函数将指定的时间戳截断到最近的指定的时间间隔的开始。
  8. date_trunc

    PostgreSQL date_trunc() 函数将一个指定的时间戳或间隔值截断到指定的部分并返回。
  9. extract

    PostgreSQL extract() 函数将指定的时间戳截断到最近的指定的时间间隔的开始。
  10. isfinite

    PostgreSQL isfinite() 函数检测一个给定的日期、时间戳或间隔值是否是有限大的。
  11. justify_days

    PostgreSQL justify_days() 函数转换时间间隔的表示方法,将超过 30 天的天数转为月数。
  12. justify_hours

    PostgreSQL justify_hours() 函数转换时间间隔的表示方法,将超过 30 天的天数转为天数。
  13. justify_interval

    PostgreSQL justify_interval() 函数转换时间间隔的表示方法,将超过 24 小时的小时数转为天数,并且将超过 30 天的天数转为月数。
  14. localtime

    PostgreSQL localtime 函数返回当前的系统时间,格式为 HH:MM:SS.ssssss
  15. localtimestamp

    PostgreSQL localtimestamp() 函数返回所属的事务开始的系统日期和时间。
  16. make_date

    PostgreSQL make_date() 函数从年、月、日字段创建一个日期。
  17. make_interval

    PostgreSQL make_interval() 函数从给定的年、月、日、时、分、秒字段创建一个间隔值。
  18. make_time

    PostgreSQL make_time() 函数从给定的时、分、秒字段创建一个时间。
  19. make_timestamp

    PostgreSQL make_timestamp() 函数从年、月、日、时、分、秒字段创建一个时间戳值。
  20. make_timestamptz

    PostgreSQL make_timestamptz() 函数从给定的年、月、日、时、分、秒、时区字段创建一个带有时区信息的时间戳值。
  21. now

    PostgreSQL now() 函数返回所属的事务开始时的系统日期和时间。
  22. pg_sleep

    PostgreSQL pg_sleep() 函数将当前服务器进程的执行暂停(睡眠)指定的秒数。
  23. pg_sleep_for

    PostgreSQL pg_sleep_for() 函数接收一个间隔参数,将当前服务器进程的执行暂停(睡眠)指定的间隔。
  24. pg_sleep_until

    PostgreSQL pg_sleep_until() 函数接收一个时间戳值,将当前服务器进程的执行暂停(睡眠)到这个指定的时刻。
  25. statement_timestamp

    PostgreSQL statement_timestamp() 函数返回所在的语句开始执行时的时间戳。
  26. timeofday

    PostgreSQL timeofday() 函数返回此函数执行时的日期和时间。同一个语句中的两次执行 timeofday() 的返回值可能不同。
  27. to_date

    PostgreSQL to_date() 函数根据给定的格式将指定的字符串转为一个日期值。
  28. to_timestamp

    PostgreSQL to_timestamp() 函数将 Unix 纪元时间转为一个标准的带时区信息的时间戳,或者根据给定的格式将指定的字符串转为时间戳。
  29. transaction_timestamp

    PostgreSQL transaction_timestamp() 函数返回所属的事务开始时的系统日期和时间。