SQLTeam.com | Weblogs | Forums

How to find a record between two dates

sql2008r2

#1

i have tried but not getting a proper result

Select * from tablename where (varchar(10),Columnname,103) between (varchar(10),getdate()-15,103) and (varchar(10),getdate(),103)


#2

i got my answer

select * from task where statusdate BETWEEN DATEADD(day,-15,GETDATE()) AND DATEADD(day,-10,GETDATE())


#3

DECLARE @StartDate DATE = '2013-01-01' , @EndDate DATE = '2013-05-01' SELECT * FROM task WHERE DATEDIFF(DAY,statusdate,@StartDate) <= 0 AND DATEDIFF(DAY,statusdate,@EndDate) >= 0 ORDER BY statusdate


#4

Keep in mind that when you do this you are including the time portion as well. So if statusdate column stores the time portion also (rather than just date), and if you are running this query at 11:30 AM on a given day, the results returned will include rows for which statusdate is 11:30 AM 15 days ago or later, but it will not include results earlier than that - for example, rows where statusdate is at 9:30 AM 15 days ago will not be included.