Click here to Skip to main content
15,797,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to calculate date difference using flowing query but it does not work. Please advise.

SQL
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
Posted
Updated 14-Feb-12 23:54pm
v2
Comments
Simon_Whale 15-Feb-12 5:26am    
In what way doesn't it work? no results? wrong results?

How is the DateReturn setup?

Try reversing the order:
SQL
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, GETDATE(), DateReturn) =3
Your way returns when it is 3 days overdue...
 
Share this answer
 
Comments
Furqan Sehgal 15-Feb-12 5:35am    
Thanks ! the error is
Generated Select Command
Failed to get Schema for the table
First of all, take a look here[^] and here[^]

SQL
SELECT [ID], GETDATE() AS [ThisDay], [DateReturn], CONVERT(INT, GETDATE() - [DateReturn]) AS [DayDifference]
WHERE DATEDIFF(day, [DateReturn],GETDATE()) =3
ORDER BY [ID]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900