Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Date/TIme Question

Status
Not open for further replies.

mlocurci

MIS
Oct 17, 2001
210
0
0
US
I really hate dealing with dates and times in queries. And again, I find myself pulling my hair our.

I need to find all completedates for yesterday, so i want from 12 Midnight to 12 Midnight. How can I do that? Here is what I am using, but its wrong. How do I normalize to

2008-06-24 00:00:00.000 to 2008-06-24 23:59:59.999

WHERE ((MESSAGESENDERCATEGORYVIEW.CompleteDATE >=getdate()-1)and (MESSAGESENDERCATEGORYVIEW.CompleteDATE <getdate())

 
Give this a try:
Code:
WHERE MESSAGESENDERCATEGORYVIEW.CompleteDATE >= DateAdd(Day, DateDiff(Day, 0, GetDate()), 0) AND
      MESSAGESENDERCATEGORYVIEW.CompleteDATE <  DateAdd(Day, DateDiff(Day, 0, GetDate() + 1 ), 0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top