Solved

How to calculate age from birthdate in SSRS

Posted on 2014-03-13
8
3,454 Views
Last Modified: 2014-03-13
Hello Experts,

I'm using Report Builder 3.0 and have a dataset which has birth dates of users (mm/dd/yyyy).  I've added a table to my report showing some basic data of users per row and added an Age column.  

Can anyone help me to calculate the age per user and populate their age in the new column?  I've tried some expressions, with no luck.  This is the last expression I tried:
=DATEDIFF(DateofBirth, getDate())

Open in new window

Screenshot for Report Builder Age CalculationExtra Info:
SQL Server Reporting Services 2008 R2
Report Builder 3.0

Any help is much appreciated, thank you.
0
Comment
Question by:Modifier1000
  • 4
  • 4
8 Comments
 

Author Comment

by:Modifier1000
Comment Utility
Well, I got this far:
=DateDiff("yyyy", Fields!DateofBirth.Value, Now())

Open in new window


It gives me the year, but it rounds up, now I just need to get year and month for a more exact date.  Also, any users without a birthdate entered, the Age value is 2013.  So I have about 20 users where someone did not enter their birthdate and their age shows 2013.Age is 2013 for users w/o birthdates entered
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
Use:

DATEDIFF(YY,DateofBirth, getDate())
0
 

Author Comment

by:Modifier1000
Comment Utility
You suggest that for the Expression of a field in Report Builder (SSRS)?
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
That is the SQL syntax and I saw you tried it but wrongly.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 26

Accepted Solution

by:
Zberteoc earned 500 total points
Comment Utility
To avoid the "rounding" issue You can try with months instead of years in you report formula, which I would now from the top of my head. Something like:

 DateDiff("mm", Fields!DateofBirth.Value, Now())/12
0
 

Author Comment

by:Modifier1000
Comment Utility
Ahhh, ok.

Well, I used your above expression and did a little massaging to get the following expression, which works:
=Round((DateDiff("m", Fields!DateofBirth.Value, Now()))/12, 1)

Open in new window


Now I just need to figure out how to remove 2013 values from the Age column w/o an entered birthdate.

Thank you for pointing me in the right direction!
0
 

Author Closing Comment

by:Modifier1000
Comment Utility
Thanks!
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
In order to get rid of that 2013 you need to replace the NULL values with Now(). I am not sure what is the syntax in SSRS but someting like:

Round((DateDiff("m", IfEmpty(Fields!DateofBirth.Value,Now()), Now()))/12, 1)

and the age in that case will return 0.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
Introduction Earlier I wrote an article about the new lookup functions (http://www.experts-exchange.com/A_3433.html) that ship with SQL Server 2008 R2.  In this article I’m going to show you another new feature of SSRS 2008 R2, this time in the vis…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now