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)
 TimeDifference

Author  Topic 

skybvi
Posting Yak Master

193 Posts

Posted - 2011-04-27 : 13:10:12
Hi,
I have a job which will be running once a day at night. it is a query whcih will return some rows depending on the data entered on that day.
For example ( 2 columns)
NAME Date
x 2011-04-24 09:55:09
y 2011-04-26 12:34:56
z 2011-04-27 10:12:14

The query should return
z 2011-04-27 10:12:14
bcoz it runs today, 27th




Regards,
Sushant
DBA
West Indies

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-27 : 13:21:11
WHERE [Date] >= DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0)
AND [Date] < DATEADD(Day, DATEDIFF(Day, 0, GetDate())+1, 0)


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-04-27 : 13:21:31
What is your actual requirement? Do you want to select all rows for a single day?

If so, maybe this will help:
SELECT *
FROM <Table Name>
WHERE [Date] >= DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 0)
AND [Date] < DATEADD(DAY, DATEDIFF(DAY, -1, CURRENT_TIMESTAMP), 0)
Go to Top of Page

skybvi
Posting Yak Master

193 Posts

Posted - 2011-04-27 : 13:41:07
Thank you both of u.


Regards,
Sushant
DBA
West Indies
Go to Top of Page
   

- Advertisement -