postgresql postgres 中的 LAST_DAY 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14229038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:58:03  来源:igfitidea点击:

LAST_DAY function in postgres

postgresql

提问by jobi88

Is there any function(s) in postgres equivalent to Oracle function LAST_DAY().

postgres 中是否有与 Oracle 函数 LAST_DAY() 等效的函数。

I need to get last day in postgres (including month and year)

我需要在 postgres 中获得最后一天(包括月份和年份)

回答by Gopinagh.R

Well, In postgres, it seems there's no such function equivalent to LAST_DAY()available in oracle.

好吧,在 postgres 中,似乎没有LAST_DAY()与 oracle 中可用的等效功能。

If you need to, you can have your own in the following ways as a

如果需要,您可以通过以下方式拥有自己的

Select Query

选择查询

SELECT (date_trunc('MONTH', now()) + INTERVAL '1 MONTH - 1 day')::date;

plsql Function

plsql 函数

        CREATE OR REPLACE FUNCTION last_day(date)
        RETURNS date AS
        $$
        SELECT (date_trunc('MONTH', ) + INTERVAL '1 MONTH - 1 day')::date;
        $$ LANGUAGE 'sql'
        IMMUTABLE STRICT;

Hope this helps.

希望这可以帮助。

回答by Abi naga Balan

create or replace funCtion last_day(fromdt anyelement)
returns date as
$BODY$
  SELECT (date_trunc('MONTH', cast(fromdt as date)) + INTERVAL '1 MONTH - 1 day')::date;
$BODY$
  LANGUAGE sql VOLATILE
  COST 100;
  ALTER FUNCTION last_day(anyelement)
    OWNER TO postgres;