Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I query for records older than 3 months to the day? 2

Status
Not open for further replies.

hockEdeals

Programmer
Mar 23, 2004
3
US
How do i select items in my database older than 3 months. I'm using getdate() to store it when it's created and i want to query items that are older than 3 monts. I'm using smalldatetime in the field.
 
In the end i want to automatically delete all entries older than 3 months. They are users who are inactive. The field is called LastLoginDate and i'm using GetDate() to store it initially whenever the user logs on, it will update. I want to be able to click a button and run a delete where LastLoginDate in Table UserData where date is older than 3 months. I tried yours but and it gave me 2003-12-23 12:25:54.233. Any Ideas? Thanks in advance!
 
2003-12-23 12:25:54.233 is 3 months ago...not sure what else you need

Code:
delete from table
where lastlogindate<DATEADD(MONTH, -3, GETDATE())
???
 
2003-12-23 13:40:25 IS three months ago as of the moment I typed this. If that's not what you want, then what DO you want?

-SQLBill
 
lol, that's was right i just didn't know how to write it as a select statement with where. Sorry, that's exactly what i needed. THANKS SQLBILL & CHECKAI!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top