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
 General SQL Server Forums
 New to SQL Server Programming
 Select Statement where "date field" equals today

Author  Topic 

aharvestofhealth
Yak Posting Veteran

52 Posts

Posted - 2012-09-29 : 18:24:49
I am trying to create a statement to return all records where the "lst_maint_dt" field is equal to today (or basically any time today). I've tried the following:

select item_no
from im_item
where lst_maint_dt = DAY(GETDATE())

That obviously does not work. Any suggestions?

malpashaa
Constraint Violating Yak Guru

264 Posts

Posted - 2012-09-29 : 19:29:29
Try something like this:

SELECT item_no
FROM im_item
WHERE lst_maint_dt >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
AND lst_maint_dt < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 1)
Go to Top of Page

aharvestofhealth
Yak Posting Veteran

52 Posts

Posted - 2012-10-01 : 13:55:38
Thanks!
Go to Top of Page
   

- Advertisement -