如何在postgresql中获取一个月的天数 [英] How to get the number of days in a month in postgresql

查看:3009
本文介绍了如何在postgresql中获取一个月的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在plpgsql中获取以下内容:

  select day_in_month(2); 

预期输出

 code> 28 

有没有内置的,我在postgres中缺少这样做?

解决方案

  SELECT 
DATE_PART('days',
DATE_TRUNC ('month',NOW())
+'1 MONTH':: INTERVAL
- '1 DAY':: INTERVAL

/ pre>

替换 NOW()与任何其他日期。


I am trying to get the following in plpgsql:

select day_in_month(2);

Expected output

28

Is there any built in that I am missing in postgres to do that?

解决方案

SELECT  
    DATE_PART('days', 
        DATE_TRUNC('month', NOW()) 
        + '1 MONTH'::INTERVAL 
        - '1 DAY'::INTERVAL
    )

Substitute NOW() with any other date.

这篇关于如何在postgresql中获取一个月的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆