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
 Transact-SQL (2000)
 Date Time Question

Author  Topic 

Session101
Starting Member

15 Posts

Posted - 2005-02-07 : 17:46:32
I am writing a stored procedure that is trying to find the rows that have a timestamp >= today's date at 3PM.
(ex: stamp >= '2/7/2005 15:00)

What would be the correct way to do this without explicity writing the date in this condition? I am not sure how to include the getdate() with my timestamp requirement. Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-02-07 : 17:48:12
timestamp >= DATEADD(hh, 15, CONVERT(varchar(10), GETDATE(), 101))

Tara
Go to Top of Page

Session101
Starting Member

15 Posts

Posted - 2005-02-08 : 17:25:24
Thank you Tara for your quick response. If I wanted to look at the rows that have a timestamp >= Yesterday @ 3PM, what would be the ebst way to do so?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-02-08 : 17:28:48
Then you'll need to subtract a day from GETDATE() using DATEADD.

Tara
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-08 : 17:30:09
Where timestamp >= dateadd(hh,15,convert(varchar,getdate()-1,101))

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-02-08 : 17:32:09
Trying not to give all the answers...they need to learn by opening up SQL Server Books Online. I had already provided most of the solution and a hint to the rest, should be enough for him to try it out on his own.

Tara
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-02-08 : 17:35:28
my bad ... I actually didn't notice you had already answer at first...

Session101 - look in BOL first per Tara... and everyone else here as a matter of fact.

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2005-02-08 : 20:51:38
Tara,

Granting complete and concise answers only ensures our continued awe and respect for your wisdom, Warrior Queen!

And this comes from an actual Warrior--me!



Semper fi, Xerxes, USMC(Ret.)
----------------------------------------------
"If cursors were nickels, I could park in town--all year!"
Go to Top of Page
   

- Advertisement -