MichaelaLee
Programmer
Hi Everyone,
I'm working on a UDF that will tell me if a date falls within a Date range. The catch is I can't look at the Day part of the date as a comparision. In other words, If I have the following:
LookUpDate = 6/25/2004
StartDate = 2/1/2004
EndDate = 2/5/2005
The UDF should only look at it like this:
LooupDate = 6/2004
StartDate = 2/2004
EndDate = 2/2005
Then see if the LookUpDate falls between the other dates.
Here is some test code I'm working with:
Use Attendance
go
Declare @FromDate smalldatetime
Declare @ToDate smalldatetime
Declare @FP smalldatetime
Select @FP = '6/25/2004'
Select @FromDate = '2/01/2004'
Select @ToDate = '2/20/2005'
if datepart(m, @FP) >= datepart(m, @FromDate) and datepart(m, @FP) <= datepart(m, @ToDate)
begin
if datepart(yyyy, @FP) >= datepart(yyyy, @FromDate) and datepart(yyyy, @FP) <= datepart(yyyy, @ToDate)
Print '1'
Else
Print '0'
End
Else
Print '0'
This code is still in the works, because if don't work right with the dates given above. I'm working on it know, but I wanted to see if others have needed something like this before. If so, How did you all handle it. Thanks for any tips or advice.
Michael Lee
I'm working on a UDF that will tell me if a date falls within a Date range. The catch is I can't look at the Day part of the date as a comparision. In other words, If I have the following:
LookUpDate = 6/25/2004
StartDate = 2/1/2004
EndDate = 2/5/2005
The UDF should only look at it like this:
LooupDate = 6/2004
StartDate = 2/2004
EndDate = 2/2005
Then see if the LookUpDate falls between the other dates.
Here is some test code I'm working with:
Use Attendance
go
Declare @FromDate smalldatetime
Declare @ToDate smalldatetime
Declare @FP smalldatetime
Select @FP = '6/25/2004'
Select @FromDate = '2/01/2004'
Select @ToDate = '2/20/2005'
if datepart(m, @FP) >= datepart(m, @FromDate) and datepart(m, @FP) <= datepart(m, @ToDate)
begin
if datepart(yyyy, @FP) >= datepart(yyyy, @FromDate) and datepart(yyyy, @FP) <= datepart(yyyy, @ToDate)
Print '1'
Else
Print '0'
End
Else
Print '0'
This code is still in the works, because if don't work right with the dates given above. I'm working on it know, but I wanted to see if others have needed something like this before. If so, How did you all handle it. Thanks for any tips or advice.
Michael Lee