Reputation: 4997
I need to calculate date difference using flowing query but it does not work. Please advise.
SELECT ID, VoucherNo, DateRec, ProductID, Description, ClaimantCo, ClaimantName, City, Phone, DateReturn, ReqJob, WSIns, Remarks, Status, Part1, Part2, Part3, Part4, OtherWSCharges, FDCharges, P1Charges, P2Charges, P3Charges, P4Charges, DateJobBegun, DateJobDone, WSRemarks, TotChargesFromWS, DeliveryStatus, DateDelivered
FROM tblClaims
WHERE DateDiff(dd, DateReturn, GETDATE()) =3
My purpose is to get records for which three days are left to DateRetun, comparing to today's date.
Thanks
Upvotes: 1
Views: 1195
Reputation: 5251
I think you've just got the datediff parameters the wrong way round - if you're looking for three days in the future you want to say:
datediff(dd, getdate(), DateReturn) = 3
Upvotes: 2
Reputation: 31239
Maybe something like this (if DateReturn is a datetime):
SELECT
DateReturn
FROM
tblClaims
WHERE
tblClaims.DateReturn BETWEEN GETDATE()-3 AND GETDATE()
Upvotes: 0
Reputation: 3438
What is DateReturn datatype? I have tested as follow. If DateReturn datatype is DateTime, it should work.
declare @dt datetime
set @dt = dateadd(day,-3, getdate())
select datediff(dd,@dt, getdate())
result is 3
Upvotes: 0