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)
 Date =Today

Author  Topic 

sz1
Aged Yak Warrior

555 Posts

Posted - 2010-10-29 : 10:25:56
Help, why is date fields so awkward.

How do I remove the date fields below to make the offeringTime = today, so it just refreshes the select statement for today only without input.
Basically this need to: (OfferingTime >= '2010/10/29 08:00:00')
be (OfferingTime = TODAY)
Thanks

SELECT COUNT(CallID) AS TotalRedirects
FROM Calls
WHERE (DeviceType = 'A')
AND (DisconnectedTime IS NOT NULL)
AND (OfferingTime >= '2010/10/29 08:00:00')
AND (OfferingTime <= '2010/10/29 18:00:00')
AND (RedirectingIDName = 'MyFQ(5555)')
GO

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-10-29 : 10:30:47
There's a number of ways, but these posts have the best solutions:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64755
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64759

These and other date-related threads are summarized here:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-29 : 11:09:44
[code]
select
TodayAt0800 = dateadd(dd,dateDiff(dd,0,getdate()),'08:00'),
TodayAt1800 = dateadd(dd,dateDiff(dd,0,getdate()),'18:00')[/code]
Results:
[code]TodayAt0800 TodayAt1800
----------------------- -----------------------
2010-10-29 08:00:00.000 2010-10-29 18:00:00.000
[/code]

CODO ERGO SUM
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-29 : 11:13:00
That's cool!
I never would have the idea to try that - nice to know now


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2010-10-29 : 11:33:12
so you're saying this then:

SELECT COUNT(CallID) AS TotalRedirects,
TODAYAT0800 = dateadd(dd,dateDiff(dd,0,getdate()),'08:00'),
TODAYAT1800 = dateadd(dd,dateDiff(dd,0,getdate()),'18:00')
FROM Calls
WHERE (DeviceType = 'A')
AND (DisconnectedTime IS NOT NULL)
AND (RedirectingIDName = 'MyFQ(5555)')
GO

Didn't know you could do field oike this TODAYAT0800, how does SQL call this?

Thanks
sz1
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-29 : 11:41:29
No, I was showing an example of how to find the DATETIME values that you wanted to use in your WHERE clause: Today at 08:00 and Today at 18:00.



CODO ERGO SUM
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2010-10-29 : 11:49:15
Ok, thanks will try this out.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2010-10-29 : 11:59:26
Cool nice one pal.
It works, you guys are groovy...

SELECT COUNT(CallID) AS TotalRedirects
FROM Calls
WHERE (DeviceType = 'A')
AND (DisconnectedTime IS NOT NULL)
AND OfferingTime >= dateadd(dd,dateDiff(dd,0,getdate()),'08:00')
AND OfferingTime <= dateadd(dd,dateDiff(dd,0,getdate()),'18:00')
AND (RedirectingIDName = 'MyFQ(5555)')
GO
Go to Top of Page
   

- Advertisement -