Problem for retriveing record using between for date datetype
-
Hi , pls help me out with this code insert into chk values('notwking',convert(datetime,getdate(),101)) the row gets inserted into the table(type varchar, type datetime). but if i try to retrive that record by this query select * from chk where dt between getdate() and getdate()+20 i dont get that tuple but i get the same with this query select * from chk where dt between getdate()-1 and getdate()+20 i thnk the problem is with the time part which is inserted during insertion. is there any solution.Pls help me out Thnks in advance
-
Hi , pls help me out with this code insert into chk values('notwking',convert(datetime,getdate(),101)) the row gets inserted into the table(type varchar, type datetime). but if i try to retrive that record by this query select * from chk where dt between getdate() and getdate()+20 i dont get that tuple but i get the same with this query select * from chk where dt between getdate()-1 and getdate()+20 i thnk the problem is with the time part which is inserted during insertion. is there any solution.Pls help me out Thnks in advance
Always use DateDiff when working with date. Syntax: DATEDIFF([datepart], [firstdate], [seconddate]) where datepart can be day, month, year, etc. Example:
WHERE DATEDIFF( dd, GETDATE(), @myDate )
BETWEEN DATEDIFF( dd, GETDATE(), @dateFrom )
AND DATEDIFF( dd, GETDATE(), @dateTo )Does that help? "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia
-
Hi , pls help me out with this code insert into chk values('notwking',convert(datetime,getdate(),101)) the row gets inserted into the table(type varchar, type datetime). but if i try to retrive that record by this query select * from chk where dt between getdate() and getdate()+20 i dont get that tuple but i get the same with this query select * from chk where dt between getdate()-1 and getdate()+20 i thnk the problem is with the time part which is inserted during insertion. is there any solution.Pls help me out Thnks in advance
-
try this out ... i.e. insert into chk values('notwking',convert(char,getdate(),105) the time part will be removed. vivek
-
Hi, thks fr the advice but insert into chk values('notwking',convert(char,getdate(),105) is actually trying to insert char datatype into datetime field right. regards -- modified at 5:25 Wednesday 21st June, 2006