sql – 如何在postgres中获取月份的最后一天?

栏目: 数据库 · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/28186014/how-to-get-the-last-day-of-month-in-postgres

如何在postgres中查找月份的最后一天?

我有一个日期列存储为数字(18)格式(YYYYMMDD)

我正在尝试使用它来约会

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

然后找到这个日期的最后一天:

像这样:

(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版本:

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

只需使用 last_day

功能:

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

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

翻译自:https://stackoverflow.com/questions/28186014/how-to-get-the-last-day-of-month-in-postgres


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Developing Large Web Applications

Developing Large Web Applications

Kyle Loudon / Yahoo Press / 2010-3-15 / USD 34.99

As web applications grow, so do the challenges. These applications need to live up to demanding performance requirements, and be reliable around the clock every day of the year. And they need to withs......一起来看看 《Developing Large Web Applications》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试