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
LAST_DAY function in postgres
提问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;