user6363065 user6363065 - 1 year ago 78
SQL Question

last hour(not add -1hr) data in sql

I am trying to get last hour data such a that, if getdate() is returning me '2016-11-14 13:09:09.653' then i want data from '2016-11-14 11:00:00.000' to '2016-11-14 12:00:00.000' not just 12:09 to 01:00.

Answer Source

Another option (assuming SQL Server 2012+)

Select Format(DateAdd(HH,-2,GetDate()),'yyyy-MM-dd HH:00:00')
      ,Format(DateAdd(HH,-1,GetDate()),'yyyy-MM-dd HH:00:00')


(No column name)      (No column name)
2016-11-14 12:00:00   2016-11-14 13:00:00
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download