Limit records to X days ago

Results 1 to 2 of 2

Thread: Limit records to X days ago

  1. #1
    Join Date
    Dec 1969

    Default Limit records to X days ago

    Hello,<BR><BR>How would I have a query return only records from 30 days ago?<BR><BR>Thank<BR>Eric

  2. #2
    Join Date
    Dec 1969

    Default RE: Limit records to X days ago

    You would need a column in your table that stored the date the row was inserted. This column name, say it is called DateEntered, would be of date/time. You could set its default to be getdate() and it would be entered for you automatically each time you entered a new row into the table.<BR><BR>Anyway, now that you have this DateEntered, use DateDiff to only get records that are 30 days old:<BR><BR>SELECT * FROM Table1<BR>WHERE DateDiff(D,DateEntered,getdate()) &#060; 30<BR><BR>See SQL books online for more information about DateDiff and getdate().<BR><BR>Happy Programming!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts