 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Larry Killen Guest
|
Posted: Wed Mar 23, 2005 9:57 pm Post subject: Is there a better way to filter on today in MS/SQL? |
|
|
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
|
Posted: Wed Mar 23, 2005 10:13 pm Post subject: Re: Is there a better way to filter on today in MS/SQL? |
|
|
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
|
Posted: Wed Mar 23, 2005 10:14 pm Post subject: Re: Is there a better way to filter on today in MS/SQL? |
|
|
| Quote: | Is there something more elegant?
So I guess not.  |
|
|
| Back to top |
|
 |
Maurice Telkamp Guest
|
Posted: Thu Mar 24, 2005 8:12 am Post subject: Re: Is there a better way to filter on today in MS/SQL? |
|
|
"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
....unless this is not what you wanted...
Maurice Telkamp
|
|
| Back to top |
|
 |
Roman Krejci Guest
|
Posted: Thu Mar 24, 2005 9:07 am Post subject: Re: Is there a better way to filter on today in MS/SQL? |
|
|
"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
|
Posted: Fri Mar 25, 2005 7:52 am Post subject: Re: Is there a better way to filter on today in MS/SQL? |
|
|
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
|
Posted: Sat Mar 26, 2005 3:40 am Post subject: Re: Is there a better way to filter on today in MS/SQL? |
|
|
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 |
|
 |
|
|
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
|
|