• 技术文章 >数据库 >PostgreSQL

    postgresql如何计算两日期间有多少天

    yangyang2020-04-05 13:21:55原创7686

    postgresql中计算时间差的方法:

    date_part() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等。

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    select now()

    ---------------------

    2018-02-01 15:49:15

     

    select date_part('year',now())

    ---------------------

    2018

    select date_part('day',now())

    ---------------------

    1

    可以通过date_part计算两个时间相差几天,几分钟,几秒钟等。

    1

    2

    3

    select date_part('day','2018-01-31 15:49:15'::timestamp-'2018-01-10 10:12:15'::timestamp)

    ---------------------

    21

    推荐:PostgreSQL教程

    专题推荐:postgresql
    上一篇:postgresql怎么查数据库信息 下一篇:postgresql判断是否为数字的方法

    相关文章推荐

    • PostgreSQL停止不了怎么办• 如何赋予postgresql数据库表权限• postgresql怎么建库• postgresql怎么关闭服务器

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网