database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
ㆍPostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
PostgreSQL Q&A 2991 게시물 읽기
No. 2991
날짜 계산함수 -- DATE_ADD(), DATE_SUB()
작성자
정재익
작성일
2001-06-21 23:30
조회수
2,481

원본출처 : http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=21

 

 

Submitted on: 03-16-2001

Description:

Simple functions to add/subtract dates. Prototypes: DATE_ADD(DATE,INT,PERIOD) DATE_SUB(DATE,INT,PERIOD) Where PERIOD is one of 'DAYS','MONTHS',or 'YEARS'. examples: SELECT DATE_ADD('1999-12-31',1,'DAYS') will produce '2001-01-01'

Code:

 

-- DATE_ADD, DATE_SUB date manipulation functions

-- Copyright (C) 2001 Mark Steele (msteele@inet-interactif.com)

--

-- 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

CREATE FUNCTION DATE_ADD(date,int4,text) RETURNS DATE AS '

DECLARE

var1 date;

var2 text;

BEGIN

var2 = $2 || '' '' || $3;

SELECT INTO var1

to_date($1 + var2::interval, ''YYYY-MM-DD'');

RETURN var1;

END;' LANGUAGE 'plpgsql';

CREATE FUNCTION DATE_SUB(date,int4,text) RETURNS DATE AS '

DECLARE

var1 date;

var2 text;

BEGIN

var2 = $2 || '' '' || $3;

SELECT INTO var1

to_date($1 - var2::interval, ''YYYY-MM-DD'');

RETURN var1;

END;' LANGUAGE 'plpgsql';

[Top]
No.
제목
작성자
작성일
조회
2994이전 시간표와 겹치지 않는지 check 하는 함수
정재익
2001-06-21
1710
2993두 datetime 사이의 overlap interval 구하기
정재익
2001-06-21
2041
2992다른 time zone 으로 시간 변경하기
정재익
2001-06-21
1840
2991날짜 계산함수 -- DATE_ADD(), DATE_SUB()
정재익
2001-06-21
2481
2990Tree-structure functions (3)
정재익
2001-06-21
1680
2989Tree-structure functions (2)
정재익
2001-06-21
1967
2988Tree-structure functions (1)
정재익
2001-06-21
2080
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다