2008-11-01 09:07:34 +07:00
|
|
|
/*
|
|
|
|
*This file is part of Adempiere ERP Bazaar
|
|
|
|
*http://www.adempiere.org
|
|
|
|
*
|
|
|
|
*Copyright (C) 2007 Low Heng Sin
|
|
|
|
*Copyright (C) 1999-2006 ComPiere, inc
|
|
|
|
*
|
|
|
|
*This program is free software; you can redistribute it and/or
|
|
|
|
*modify it under the terms of the GNU General Public License
|
|
|
|
*as published by the Free Software Foundation; either version 2
|
|
|
|
*of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*This program is distributed in the hope that it will be useful,
|
|
|
|
*but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
*GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*You should have received a copy of the GNU General Public License
|
|
|
|
*along with this program; if not, write to the Free Software
|
|
|
|
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of
|
|
|
|
*/
|
|
|
|
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE)
|
2010-04-28 06:30:29 +07:00
|
|
|
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
2008-11-01 09:07:34 +07:00
|
|
|
BEGIN
|
|
|
|
RETURN CAST(datetime AS DATE);
|
|
|
|
END;
|
2014-05-31 00:11:20 +07:00
|
|
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
2008-11-01 09:07:34 +07:00
|
|
|
|
2017-08-25 17:37:40 +07:00
|
|
|
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITHOUT TIME ZONE)
|
|
|
|
RETURNS TIMESTAMP WITHOUT TIME ZONE AS $$
|
|
|
|
BEGIN
|
|
|
|
RETURN CAST(datetime AS DATE);
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
|
|
|
|
2022-11-21 19:56:25 +07:00
|
|
|
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITHOUT TIME ZONE, format varchar)
|
2010-04-28 06:30:29 +07:00
|
|
|
RETURNS DATE AS $$
|
2008-11-01 09:07:34 +07:00
|
|
|
BEGIN
|
|
|
|
IF format = 'Q' THEN
|
|
|
|
RETURN CAST(DATE_Trunc('quarter',datetime) as DATE);
|
|
|
|
ELSIF format = 'Y' or format = 'YEAR' THEN
|
|
|
|
RETURN CAST(DATE_Trunc('year',datetime) as DATE);
|
|
|
|
ELSIF format = 'MM' or format = 'MONTH' THEN
|
|
|
|
RETURN CAST(DATE_Trunc('month',datetime) as DATE);
|
|
|
|
ELSIF format = 'DD' THEN
|
|
|
|
RETURN CAST(DATE_Trunc('day',datetime) as DATE);
|
|
|
|
ELSIF format = 'DY' THEN
|
|
|
|
RETURN CAST(DATE_Trunc('day',datetime) as DATE);
|
|
|
|
ELSE
|
|
|
|
RETURN CAST(datetime AS DATE);
|
|
|
|
END IF;
|
|
|
|
END;
|
2014-05-31 00:11:20 +07:00
|
|
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
2008-11-01 09:07:34 +07:00
|
|
|
|
2022-11-21 19:56:25 +07:00
|
|
|
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar)
|
|
|
|
RETURNS DATE AS $$
|
|
|
|
BEGIN
|
|
|
|
RETURN trunc(cast(datetime as timestamp without time zone), format);
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
|
|
|
|
2008-11-01 09:07:34 +07:00
|
|
|
CREATE OR REPLACE FUNCTION trunc(i INTERVAL)
|
|
|
|
RETURNS INTEGER AS $$
|
|
|
|
BEGIN
|
|
|
|
RETURN EXTRACT(DAY FROM i);
|
|
|
|
END;
|
2014-05-31 00:11:20 +07:00
|
|
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
|
|
|
|