|
|
Question : query data for the last hour
|
|
Hi,
Please kindly assist how can we query records for the last hour?
present time is 2:40
getdate() - 1hour
dtcolumn= datetime
select * from table1 where dtcolumn>=one hour ago which is 1:00
and dtcolumn
Thanks.
|
Answer : query data for the last hour
|
|
declare @start datetime,@end datetime set @start=dateadd(h,-1,convert(char(8),getdate(),112) +' '+ Right('0' + convert(varchar(2),datepart(h,getdate()),2) ) + ':00:00') set @end=Dateadd(h,+1,@start) select * from table1 where dtcolumn between @start and @end
|
|
|
|
|