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 2000 Forums
 SQL Server Development (2000)
 SQL Date question

Author  Topic 

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2008-08-29 : 10:42:10
I am trying to run a query every night that includes a where clause like this -

Date between Todays date 00:00:000 and getdate()

So basically running a between off the first midnight of that day against whatever time date is when its run.

any suggestions?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-29 : 10:44:14
SELECT DATEADD(d, DATEDIFF(d, 0, GetDate()), 0), GetDate()

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-29 : 10:46:32
[code]SELECT *
FROM YourTable
WHERE datefield>=DATEADD(d,DATEDIFF(d,0,GETDATE()),0)
AND datefield<DATEADD(d,DATEDIFF(d,0,GETDATE())+1,0)[/code]
Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2008-08-29 : 10:51:30
That was quick!

Thank you
Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2008-08-29 : 10:58:24
In anyone wondered -

I ended up using this

between DATEADD(d, DATEDIFF(d, 0, GetDate()), 0) and GetDate()
Go to Top of Page
   

- Advertisement -