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)
 datetime query

Author  Topic 

nic
Posting Yak Master

209 Posts

Posted - 2002-11-21 : 14:28:19
Hi, I have a table containing a user key and an expired date (datetime field). I need to run a query that returns all records where the expired date is equal or less than today's date. But the trick is that I don't want to take into account the time part of the datetime field. For example:

tblExpired
key expiredDate
1 1/12/2002 12:01AM
2 2/23/2002 1:04AM
3 2/23/2002 9:00PM
4 2/24/2002 7:00AM

If today's date is 2/23/2002 and I run the query at 10AM, I want to get keys 1,2 and 3 returned (key 3 is technically later than the time, but as I said the expired date is based only on the date)

This query won't work since it will only return keys 1 and 2
Select key from tblExpired WHERE expiredDate <= getDate()

I'm sure there is an easy way to do this but I just don't see how.

Thanks in advance

Nic

burbakei
Yak Posting Veteran

80 Posts

Posted - 2002-11-21 : 14:52:40
Select key from tblExpired WHERE CONVERT(VARCHAR, expiredDate, 101) <= CONVERT(VARCHAR, getDate(), 101)

Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-11-21 : 15:04:32
Arnoldbot:
WHERE expiredDate < DATEADD(d, DATEDIFF(d, 0, GETDATE())+1, 0)


Edited by - Arnold Fribble on 11/21/2002 15:07:47
Go to Top of Page
   

- Advertisement -