SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Statement where "date field" equals today
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aharvestofhealth
Yak Posting Veteran

USA
52 Posts

Posted - 09/29/2012 :  18:24:49  Show Profile  Reply with Quote
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

Saudi Arabia
260 Posts

Posted - 09/29/2012 :  19:29:29  Show Profile  Reply with Quote
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)

Edited by - malpashaa on 09/29/2012 19:30:48
Go to Top of Page

aharvestofhealth
Yak Posting Veteran

USA
52 Posts

Posted - 10/01/2012 :  13:55:38  Show Profile  Reply with Quote
Thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000