Reputation: 24102
So each record on my table has a datetime
timestamp column.
How do I return the age (in hours), of these records in the database?
Thank you!
Upvotes: 1
Views: 709
Reputation: 9332
Since datediff(hour,'2000-01-01 00:59','2000-01-01 01:00')
returns 1, due to the (counterintuitive) way datediff
works, you may want something more accurate:
select DATEDIFF(minute,the_timestamp,getdate()) / 60
from TheTable
Upvotes: 0
Reputation: 35464
Use the datediff function.
select datediff(hour, getdate(), dob) as age
from ...
Upvotes: 0
Reputation: 28894
select DATEDIFF(hour,timestamp,getdate()) as hours_old
from myTable
Upvotes: 2
Reputation: 2714
datediff(hour,[Your Column], getdate())
http://msdn.microsoft.com/en-us/library/ms189794.aspx
Upvotes: 2