Hi Bhavesh23,
Please refer below SQL query.
SQL
DECLARE @DateofBirth DATETIME
DECLARE @CurrentDatetime DATETIME
DECLARE @Years VARCHAR(40)
DECLARE @Months VARCHAR(30)
SET @DateofBirth ='2001-01-27'
SET @CurrentDatetime =GETDATE()
SELECT @Years=DATEDIFF(YEAR,@DateofBirth,@CurrentDatetime)
SELECT @Months=DATEDIFF(MONTH,@DateofBirth,@CurrentDatetime)-(DATEDIFF(YEAR,@DateofBirth,@CurrentDatetime)*12)
SELECT @Years +' years, ' +@Months +' months' as YearNMonth
Output
YearNMonth |
21 years, 11 months |