i have a datetime field in the post tables.
I would like to get the records within the latest 7 days.
Are there any functions for doing something like this?
my current query is something like
select * from post where creation_time ...
Thank you
try something like this:
create
table #test(datedatetime)insert
into #testvalues
('01/01/2007')insert
into #testvalues
('02/01/2007')insert
into #testvalues
('02/04/2007')
select
*from #testwhere
date>dateadd(day,-7,getdate())drop
table #testI think that it will point you in correct direction, or maybe it is your solution?
|||Could you not just do...
select
*from post
where
creation_time >dateadd(day,-7,getdate())
jpazgier, i am not following the reason for creating the additional table.
|||I just try to provide working example in my answer so I created temporary table with my test data to show that it works and for future testing.
But in this case my example only points your how you can try to solve problem, you maybe would like to take care about not only day but also minutes?
This example if you run it at 12:31 today will show records inserted after 12:31 7 days ago so records inserted at 12:30 will be not visible and maybe author of the post would like to take care about this himself, I do not know if time of the day is important for him or not.
Thanks
|||Both answers are great!|||Both answers are great!
Thank you
No comments:
Post a Comment