Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to get content older than 3 weeks

My content table looks like (contentID, title, created). I need to get all content that was created more than 3 weeks ago.

Using a SQL Server database and created is of datetime datatype.

like image 698
mrblah Avatar asked Oct 20 '09 00:10

mrblah


2 Answers

How about:

select contentID, title, created 
from content
where created < dateadd(week,-3,getdate());

This sticks closer to the question. 21 days is fine, obviously means the same, but I find that it's good to use the terminology used in the question.

For example... a while back I was asked to survey an average of 1 in 50 visitors to a site. I described this as a proportion of 0.02, and the client wasn't happy. I pointed out to the client that they're the same, but I learned my lesson, and now if I change the way that something is described, I make sure I comment to that effect, and preferably don't change it in the first place. If the client wants 3 weeks, do it as 3 weeks, not 21 days.

like image 87
Rob Farley Avatar answered Oct 17 '22 13:10

Rob Farley


in MS SQl 2000/2005 you can do this

Select
   contactID,
   title,
   created
from
   content
where
   created < getdate()-21
like image 43
J.Hendrix Avatar answered Oct 17 '22 13:10

J.Hendrix