0

i tried to get datediff in sql with the following query,

SELECT DATEDIFF(MM,'05/05/2013',GETDATE())

it's working fine but is returning results only in terms of days/months/years depending on the parameter(DD/MM/YY) passed to DATEDIFF() function.

is their any way to get the result as, suppose in above case 0--years,7--months,0--days?

thanks

roohan
  • 13
  • 1
  • 4
  • 1
    Maybe you could take a look at this http://stackoverflow.com/questions/57599/how-to-calculate-age-in-t-sql-with-years-months-and-days – user2028185 Dec 05 '13 at 06:23
  • Note that, regardless, your chosen date format is ambiguous. On SQL Server, please always use `YYYYMMDD`. – Clockwork-Muse Dec 05 '13 at 09:41

1 Answers1

0

this should do it !!

declare @a date
set @a='2013-05-05'

select cast(datediff(yyyy, @a, cast(getdate()as date)) as varchar(10)) + 'Years : ' 

+ cast(datediff(mm, @a, cast(getdate() as date)) as varchar(10)) + 'Months : ' 

+ cast(datediff(dd, @a, cast(getdate()as date))as varchar(10)) + 'Days'
vhadalgi
  • 7,027
  • 6
  • 38
  • 67