Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to calculate age from birthdate in SSRS

Posted on 2014-03-13
8
Medium Priority
?
4,491 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
ID: 39926394
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 27

Expert Comment

by:Zberteoc
ID: 39926675
Use:

DATEDIFF(YY,DateofBirth, getDate())
0
 

Author Comment

by:Modifier1000
ID: 39926761
You suggest that for the Expression of a field in Report Builder (SSRS)?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 27

Expert Comment

by:Zberteoc
ID: 39926816
That is the SQL syntax and I saw you tried it but wrongly.
0
 
LVL 27

Accepted Solution

by:
Zberteoc earned 2000 total points
ID: 39926829
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
ID: 39926891
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
ID: 39926892
Thanks!
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39926935
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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