Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How do i search a date in a datetime col?

Author  Topic 

thephill
Starting Member

2 Posts

Posted - 2015-03-02 : 23:30:58
hi i have a column with datetime type. in the search i need to search a record by date, but now every time when i pass just the date it returns zero. how do i overcomes this problem?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2015-03-03 : 00:41:19
DECLARE @SearchDate DATETIME = '20150303';

SELECT * FROM dbo.Table1 WHERE Col1 >= @SearchDate AND Col1 < DATEADD(DAY, 1, @SearchDate);



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -