--------------->
22nd Jan, 2008

SQL Server Datediff - Duration between 2 dates

Datediff is the function for you if you want to calculate different between 2 dates, and make sure you supply the unit you would like to measure :

select ‘Year’, datediff(yyyy, ‘2005-01-22 10:20:00′, ‘2008-01-22 16:20:00′)
=> 3

select ‘Month’, datediff(m, ‘2008-01-22 10:20:00′, ‘2008-12-22 16:20:00′)
=> 11

select ‘Day’, datediff(d, ‘2008-01-22 10:20:00′, ‘2008-01-29 16:20:00′)
=> 7

select ‘Hour’, datediff(hh, ‘2008-01-22 10:20:00′, ‘2008-01-22 16:20:00′)
=> 6

select ‘Minute’, datediff(mi, ‘2008-01-22 10:20:00′, ‘2008-01-22 16:20:00′)
=> 360

select ‘Second’, datediff(s, ‘2008-01-22 10:20:00′, ‘2008-01-22 10:20:30′)
=> 30

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • De.lirio.us

Responses

Good

This was very helpful. Thanks!

Leave a response

Your response:

Categories