AccessBlog.net

News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

Wednesday, September 08, 2004

[Access] IsOverlapping()

Quite useful function to check if two periods overlapping:

Public Function IsOverlapping(ByVal Per1Beg As Date, _
ByVal Per1End As Date, _
ByVal Per2Beg As Date, _
ByVal Per2End As Date) As Boolean
If Per1Beg <= Per2Beg And Per1End <= Per2Beg Then Exit Function
If Per1Beg >= Per2End Then Exit Function
IsOverlapping = True
End Function

and T-SQL version:

CREATE FUNCTION dbo.fnIsOverlapping (@Per1Beg DateTime, @Per1End DateTime, @Per2Beg DateTime, @Per2End DateTime)
RETURNS int
AS
BEGIN
Declare @Result int
set @Result=1
If @Per1Beg <= @Per2Beg And @Per1End <= @Per2Beg begin set @Result=0 end else If @Per1Beg >= @Per2End
begin
set @Result=0
end
return @Result
END


0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home