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 2005 Forums
 Transact-SQL (2005)
 Retrieve todays records

Author  Topic 

Shilpa22
Starting Member

37 Posts

Posted - 2009-04-27 : 02:23:42
Hello all,

I need to retrieve today records.
For example time field has the value 2009-04-27 05:57:47.320.. so i need to retireve all the records which fall in 2009-04-27.

I am unable to get the exact query, pls help me

Thanks in advance.



Thanks in Advance
Shilpa

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-27 : 02:25:00
[code]DECLARE @Today DATETIME

SET @Today = DATEDIFF(DAY, 0, GETDATE())

SELECT *
FROM Table1
WHERE Col1 >= @Today
AND Col1 < DATEADD(DAY, 1, @Today)[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Shilpa22
Starting Member

37 Posts

Posted - 2009-04-27 : 02:42:23
Thanks all,

I got the query..its working..

Select * from table_name Where Convert(varchar(12),column_name,101) = Convert(varchar(12),getdate(),101)

Thanks in Advance
Shilpa
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-27 : 02:43:22
Yes it is!
And then compare the speed between the two suggestions.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-27 : 02:55:16
quote:
Originally posted by Shilpa22

Thanks all,

I got the query..its working..

Select * from table_name Where Convert(varchar(12),column_name,101) = Convert(varchar(12),getdate(),101)

Thanks in Advance
Shilpa


Why do you convert dates to varchar and compare?
Peso showed you a correct way of doing it


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -