如何在postgres中获得月份的最后一天? [英] How to get the last day of month in postgres?

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

问题描述

如何在postgres中查找月份的最后一天?
我有一个以(YYYYMMDD)格式存储为numeric(18)的日期列
我正在尝试使用

How to find the last day os the month in postgres? I have a date columns stored as numeric(18) in the format(YYYYMMDD) I am trying it to make it date using

to_date("act_dt",'YYYYMMDD') AS "act date"

然后找到该日期的最后一天:
像这样:

then find the last day of this date: like this:

(select (date_trunc('MONTH',to_date("act_dt",'YYYYMMDD')) + INTERVAL '1 MONTH - 1 day')::date)

但它给了我这个错误:

ERROR: Interval values with month or year parts are not supported
  Detail: 
  -----------------------------------------------
  error:  Interval values with month or year parts are not supported
  code:      8001
  context:   interval months: "1"
  query:     673376
  location:  cg_constmanager.cpp:145
  process:   padbmaster [pid=20937]
  -----------------------------------------------

有帮助吗?

Postgres版本:

Postgres version:

i686-pc-linux-gnu上的PostgreSQL 8.0.2,由GCC gcc(GCC)3.4.2 20041017(Red Hat 3.4.2)编译-6.fc3),Redshift 1.0.874

推荐答案

只需使用最后一天函数:

select last_day(to_date(act_date,'YYYYMMDD'))

PS:现在,我相信您知道为自己的问题选择正确的标签非常重要!

PS: Now, i believe that you know that it is very important to choose the right tags for your own question!

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

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