Year and Month differences using DATEDIFF

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 464
	SELECT DATEDIFF(YYYY, '2010-1-10', GETDATE()) 'YEARS DIFF'
,DATEDIFF(M, '2010-1-10', GETDATE()) ' MONTHS DIFF'
,DATEDIFF(DAY, '2010-1-10', GETDATE()) ' DAYS DIFF'
,DATEDIFF(DAY, '2010-1-10', GETDATE())/365 ' YEARS'
,DATEDIFF(M, '2010-1-10', GETDATE())/12 ' YEARS'
,DATEDIFF(DAY, '2010-1-10', GETDATE())/30 'MONTHS'

/* OUTPUT
YEARS DIFF MONTHS DIFF DAYS DIFF YEARS YEARS MONTHS
4 56 1706 4 4 56

*/

NOTE: Today's DATE is 2014-09-12

Comments or Responses

Login to post response