Calculate hours difference in datetime
- by ScG
I have a series of datetime values. I want to select records with a difference of 2 or more hours between them.
2010-02-11 08:55:00.000
2010-02-11 10:45:00.000
2010-02-11 10:55:00.000
2010-02-11 12:55:00.000
2010-02-11 14:52:00.000
2010-02-11 16:55:00.000
2010-02-11 17:55:00.000
2010-02-11 23:55:00.000
2010-02-12 00:55:00.000
2010-02-12 02:55:00.000
Expected (The next date compared is with the last date that qualified for the 2 hr difference):
2010-02-11 08:55:00.000
2010-02-11 10:55:00.000
2010-02-11 12:55:00.000
2010-02-11 16:55:00.000
2010-02-11 23:55:00.000
2010-02-12 02:55:00.000
I am using SQL 2005 or 2008