Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 old of person
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

172 Posts

Posted - 09/14/2013 :  12:04:32  Show Profile  Reply with Quote
We have to value, birth date and today date.
How can we calculate years, months and days after a date (old age)?

for example according to following values(yyyymmdd) we need these values:
12 years - 10 months - 2 days

select '2000-05-29' as bithdate,'2013-04-01' as today_date

Please direct me.

Edited by - sigmas on 09/14/2013 12:08:50

Aged Yak Warrior

549 Posts

Posted - 09/14/2013 :  14:50:08  Show Profile  Reply with Quote
Something like this:

SELECT '2000-05-29' as bithdate,'2013-04-01' as today_date,  
	DATEPART(YEAR, DATEADD(DAY, 0, DATEDIFF(DAY, '2000-05-29','2013-04-01'))) - 1900 AS [YEARS],
	DATEPART(MONTH, DATEADD(DAY, 0, DATEDIFF(DAY, '2000-05-29','2013-04-01')))-1 AS [MONTHS],
	DATEPART(DAY, DATEADD(DAY, 0, DATEDIFF(DAY, '2000-05-29','2013-04-01')))-1 AS [DAYS];

Go to Top of Page

Posting Yak Master

172 Posts

Posted - 09/15/2013 :  15:02:32  Show Profile  Reply with Quote
Thank you very much.
I think no need to DATEADD function. It automatically calculate adding the days with base date.

	DATEPART(YEAR, DATEDIFF(DAY, bithdate,today_date)) - 1900 AS [YEARS],
	DATEPART(MONTH, DATEDIFF(DAY, bithdate,today_date))-1 AS [MONTHS],
	DATEPART(DAY, DATEDIFF(DAY, bithdate,today_date))-1 AS [DAYS],
	DATEPART(DAY, DATEDIFF(DAY, bithdate,today_date))-1 AS [DAYS]
VALUES('2000-05-31', '2013-04-01'),--12-10-2
)D (bithdate, today_date);
Go to Top of Page

In (Som, Ni, Yak)

17689 Posts

Posted - 09/16/2013 :  00:01:41  Show Profile  Reply with Quote
See "Finding Age" in this thread

Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000