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 2993 게시물 읽기
No. 2993
두 datetime 사이의 overlap interval 구하기
작성자
정재익
작성일
2001-06-21 23:32
조회수
2,041

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

 

 

Submitted on: 04-12-2001

Description:

This function returns the interval of time for which the two datetime ranges overlap. They are an expansion of the builtin overlaps(dt1,dt2,dt3,dt4) function. Contributed by Josh Berkus.

Code:

 

-- This function returns the interval of time for which the two

-- datetime ranges overlap.

-- By Josh Berkus

 

CREATE FUNCTION overlap_interval(DATETIME, DATETIME, DATETIME, DATETIME)

RETURNS INTERVAL AS '

DECLARE

begin1 ALIAS for $1;

end1 ALIAS for $2;

begin2 ALIAS for $3;

end2 ALIAS for $4;

overlap_amount INTERVAL;

BEGIN

--test for overlap using the ovelap function.

--if not found, return 0 interval.

 

IF NOT overlaps(begin1, end1, begin2, end2) THEN

RETURN ''00:00:00''::INTERVAL;

END IF;

--otherwise, test for the various forms of overlap

 

IF begin1 < begin2 THEN

IF end1 < end2 THEN

overlap_amount := end1 - begin2;

ELSE

overlap_amount := end2 - begin2;

END IF;

ELSE

IF end1 < end2 THEN

overlap_amount := end1 - begin1;

ELSE

overlap_amount := end2 - begin1;

END IF;

END IF;

 

RETURN overlap_amount;

END;

' LANGUAGE 'plpgsql';

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