PostgreSQL 中的 last_day [英] last_day in PostgreSQL

查看:178
本文介绍了PostgreSQL 中的 last_day的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

oracle last_day 函数返回该月的最后一天.例子:

The oracle last_day function return the last day of the month. example:

nls_date_format='YYYY-MM-DD H24:MI:SS'
select last_day(sysdate) from dual;
LAST_DAY(SYSDATE)
-------------------
2014-06-30 15:45:43

oracle 也返回时间值.

oracle return the time value as well.

我在 PostgreSQL 中尝试了以下 sql,它返回一个月的最后一天,但时间值为00:00:00".

I have tried below sql in PostgreSQL which return the last day of month but time value is "00:00:00".

select (date_trunc('month', now()) + interval '1 month -1 day')::timestamp(0);
         ?column?          
---------------------------
 2014-06-30 00:00:00
(1 row)

sql 正确返回日期,但我想要像 oracle 一样的日期和时间.

the sql return the date correctly but I want date and time like oracle.

推荐答案

select (
    date_trunc('month', now())
    + interval '1 month -1 day'
    + now()::time
)::timestamp(0);

这篇关于PostgreSQL 中的 last_day的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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