I am using datediff
in a query to return the dates that are less than 7 days from the start date.
DECLARE @d1 DATE
SET @d1 = (SELECT CurrentServiceWeek FROM Technician WHERE ID = 150)
SELECT
First_Name, Last_Name, Previous_Service_Date,
Address1, Address2, City, [State], Zip
FROM
Customer
JOIN
CustomerAddress ON Customer.ID = Customer_ID
WHERE
Technician_ID = 150
AND DATEDIFF(day, (@d1), (SELECT Previous_Service_Date
FROM Customer
WHERE Technician_ID = 150)) < 7
That datediff
is also giving me more than one result. CurrentServiceWeek
is equal to 3/11/2016 and is the start date so any dates 6 days out will suffice the query. But the dates that it returned as a Previous_Service_Date
value are:
4/5/2015
3/6/2016
So the query should only return the 3/6/2016 date. Can someone help me out so I can see where I'm going wrong please? Is DATEDIFF
ignoring the year in the date since I passed a day for the datepart
parameter?