BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is there a better way to filter on today in MS/SQL?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Larry Killen
Guest





PostPosted: Wed Mar 23, 2005 9:57 pm    Post subject: Is there a better way to filter on today in MS/SQL? Reply with quote



I played around for 5 minutes and this is the best I could come up with.
Seems I could do better.

Is there something more elegant?

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > (GETDATE()-1)


Back to top
Patrick
Guest





PostPosted: Wed Mar 23, 2005 10:13 pm    Post subject: Re: Is there a better way to filter on today in MS/SQL? Reply with quote



I use this:

WHERE CONVERT(VARCHAR(20),CONVERT(DateTime,(<insert fieldname here>)),101) =
CONVERT(VARCHAR(20),CONVERT(DateTime,(GetDate())),101)

"Larry Killen" <LarryKillen (AT) Gainco (DOT) Com> wrote

Quote:
I played around for 5 minutes and this is the best I could come up with.
Seems I could do better.

Is there something more elegant?

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > (GETDATE()-1)




Back to top
Patrick
Guest





PostPosted: Wed Mar 23, 2005 10:14 pm    Post subject: Re: Is there a better way to filter on today in MS/SQL? Reply with quote



Quote:
Is there something more elegant?
So I guess not. Smile




Back to top
Maurice Telkamp
Guest





PostPosted: Thu Mar 24, 2005 8:12 am    Post subject: Re: Is there a better way to filter on today in MS/SQL? Reply with quote


"Larry Killen" <LarryKillen (AT) Gainco (DOT) Com> wrote

Quote:
I played around for 5 minutes and this is the best I could come up with.
Seems I could do better.

Is there something more elegant?

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > (GETDATE()-1)
There is nothing wrong with this. Use it, and be proud. It took you only 5

minutes to find the most elegant solution Wink
....unless this is not what you wanted...
Maurice Telkamp



Back to top
Roman Krejci
Guest





PostPosted: Thu Mar 24, 2005 9:07 am    Post subject: Re: Is there a better way to filter on today in MS/SQL? Reply with quote


"Larry Killen" <LarryKillen (AT) Gainco (DOT) Com> píše v diskusním příspěvku
news:4241e6f3$1 (AT) newsgroups (DOT) borland.com...
Quote:
I played around for 5 minutes and this is the best I could come up with.
Seems I could do better.

Is there something more elegant?

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > (GETDATE()-1)

Uhmm.... this is not TODAY, this is
(NOW-one day ... NOW> interval.
So if the query is run, say , saturday march 26 2005 on 10am,
DateWeighed equal to friday march 25 2005 1pm
satisfy the condition.

--
Roman
mail: [email]info (AT) rksolution (DOT) cz[/email]
URL: www.rksolution.cz






Back to top
Tomislav Kardaš
Guest





PostPosted: Fri Mar 25, 2005 7:52 am    Post subject: Re: Is there a better way to filter on today in MS/SQL? Reply with quote

Hi Larry!

On Wed, 23 Mar 2005 16:57:58 -0500, "Larry Killen"
<LarryKillen (AT) Gainco (DOT) Com> wrote:

Quote:
I played around for 5 minutes and this is the best I could come up with.
Seems I could do better.

Is there something more elegant?

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > (GETDATE()-1)

this is last 24 hours, for real today see this:

WHERE DateWeighed > convert(datetime, FLOOR(convert(float,
getdate())))

1 min. :)

tomi

Back to top
Stephan Marais
Guest





PostPosted: Sat Mar 26, 2005 3:40 am    Post subject: Re: Is there a better way to filter on today in MS/SQL? Reply with quote

Not sure about performance, but the below might more elegant:
Write a udf.

create function udf_striptime(@thedate datetime)
returns datetime as
begin
declare @hour int
declare @min int
declare @sec int
declare @msec int
declare @result datetime

select @hour = datepart(hh, @thedate)
select @min = datepart(mi, @thedate)
select @sec = datepart(ss, @thedate)
select @msec = datepart(ms, @thedate)

select @result = dateadd(hh, -@hour, @thedate)
select @result = dateadd(mi, -@min, @result)
select @result = dateadd(ss, -@sec, @result)
select @result = dateadd(ms, -@msec, @result)

return @result
end

Then you can use SQL like

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > dbo.udf_striptime(getdate())

Stephan Marais

Larry Killen wrote:
Quote:
I played around for 5 minutes and this is the best I could come up with.
Seems I could do better.

Is there something more elegant?

SELECT [RecNum], [DateWeighed]
FROM [GaincoData].[dbo].[ProductionData]
WHERE DateWeighed > (GETDATE()-1)



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.