Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Calculate Age in Excel from ID Number (4 Quick Methods)

While working in Excel, you might need to obtain the age of people from their ID cards. Keeping this in mind, this tutorial aims to explain 4 quick methods on how to Calculate Age in Excel from ID Number.


Download Practice Workbook

Calculate Age.xlsm

4 Methods to Calculate Age in Excel from ID Number  

Admittedly, Microsoft Excel does not offer any built-in functions to calculate age however, we can combine a few functions to convert the date of birth to age.

Let’s consider the following dataset (in B4:C14) with the Name of people and their ID Numbers. Generally speaking, the first 6 digits in ID Numbers represent the date of birth of that person in the format yy-mm-dd.

Fortunately, we can extract the date of birth from the ID Numbers to convert them to Age in years. So, let’s explore these methods one by one.


1. Calculate Age from ID (Step-By-Step Method)

The first method combines various Excel functions to calculate age from ID numbers in an easy and step-by-step process.

1.1 Calculate Age from ID with MID Function

As the title suggests, Excel’s MID, TODAY, and INT functions are used in this method.

Steps:

  • Firstly, add a Date of Birth column and insert this formula.

=MID(C5,5,2)&"/"&MID(C5,3,2)&"/"&MID(C5,1,2)

Here, the C5 cell represents the ID Number (text argument), and the next two numbers represent the start_num and num_chars arguments respectively. In this formula, the MID function extracts the first 6 digits from the ID Number text.

  • Secondly, insert a Current Date column and type in the TODAY function which returns the present date.

=TODAY()

  • Thirdly, calculate the Age in years by calculating the difference between the two dates and dividing by 365 days.
  • Additionally, the INT function rounds the Age to the nearest whole number.

=INT((E5-D5)/365)


1.2 Using DATE Function to Extract Age from ID 

This method is similar to the previous, applying Excel’s DATE, LEFT, and INT functions.

Steps:

  • Firstly, add a Date of Birth column and insert this formula.

=DATE(LEFT(C5,2),MID(C5,3,2),MID(C5,5,2))

Here, the C5 cell represents the ID Number (text argument).

  • Then, add a  Current Date column and apply the TODAY function which returns the present date.

=TODAY()

  • Next, calculate the Age in years by calculating the difference between the two dates and dividing by 365 days.

=INT((E5-D5)/365)


2. Compute the Age from the ID Number Directly

If the first method is too much work then our next calculates the age directly without the need for extra columns. Let’s see it in action.

2.1 Calculate Age Using DATEDIF and IF Functions 

Computing the age directly blends the DATEDIF, LEFT, and the IF functions respectively, in this example, the C5 cell refers to the ID Number (text argument).

=DATEDIF(DATE(IF(LEFT(C5,2)>TEXT(TODAY(),"YY"),"19"&LEFT(C5,2),"20"&LEFT(C5,2)MID(C5,3,2),MID(C5,5,2)),TODAY(),"y")

Formula Breakdown

  • In this formula, the MID function obtains the first 6 numbers from the ID Number in the C5 cell.
  • Next, the IF function checks whether the year is less than or greater than the current year.
  • Lastly, the DATEDIF function subtracts the birth year from the present year and returns the Age.

2.2 Calculate Age with DATEDIF and DATE Functions 

Our next method simplifies the expression even more with help of the DATE function, while, directly determining the age of the person.

=DATEDIF(DATE(MID(C5,1,2),MID(C5,3,2),MID(C5,5,2)),TODAY(),"y")

In this expression, the C5 cell represents the ID Number (text argument), while, the two following numbers refer to the start_num and num_chars arguments respectively.

Formula Breakdown

  • Initially, the DATE function takes in 3 arguments (year, month, day) which are provided by the MID function.
  • Finally, the DATEDIF function returns the Age.

3. Convert ID Number to Age with Data Tools

Are you worried about writing complex expressions and combining functions? Then our third method is the answer to your prayer!

Step 01: Navigate to the Data Ribbon

  • Firstly, add a column (D5:D14) titled Date of Birth and copy & paste all ID Numbers in that column.
  • Next, select all the cells in the column and click the Text to Columns button.

Step 02: Extract the Date of Birth from the ID Number

  • Secondly, a Convert Text to Columns Wizard appears.
  • Now, in step 1, select the Fixed width button as all ID Numbers have the same number of digits.

  • Then, click to drop the cursor just after the 6th digit from the left side, as depicted in the image below.

  • Eventually, select the Date format from the drop-down and press Finish to close the dialog box.

Step 03: Calculate the Age

  • Thirdly, add a column named Current Date (E5:E14) and enter the TODAY function to get the present date.

  • In the last step, make another column for Age (F5:F14) and compute the difference between the two dates, and divide by 365 days to get the Age in years.

=INT((E5-D5)/365)


4. Using VBA Code

If you’re wondering, is there a way to define a custom function to compute Age from ID Number? Then VBA has you covered. Before we start, add a Date of Birth column and insert this formula.

=MID(C5,5,2)&"/"&MID(C5,3,2)&"/"&MID(C5,1,2)

Step 01: Open the VBA Editor

  • To begin, go to the Developer tab and then to Visual Basic.

Step 02: Insert the VBA Code

  • Secondly, insert a Module where you’ll paste the VBA code.

  • For your ease of reference, you can copy the code from here and paste it into the window as shown below.
Public Function calculate_age(birth_date As Date, Optional result_index As Integer = 0) As Variant
    today_day = Day(Date)
    today_month = Month(Date)
    today_year = Year(Date)
    birth_date_day = Day(birth_date)
    birth_date_month = Month(birth_date)
    birth_date_year = Year(birth_date)
    If birth_date_month 

Step 03: Use the Function

  • Thirdly, close the VBA window and return to your worksheet.
  • Finally, type an Equal sign followed by the calculate_age function, and enter a cell reference (D5) containing the date of birth to get the age.


Conclusion

I hope these useful methods mentioned above will answer your queries on how to calculate age in Excel from ID number. If you have any questions or feedback, please let me know in the comment section. Or you can check out our other articles on the Exceldemy website.

The post How to Calculate Age in Excel from ID Number (4 Quick Methods) appeared first on ExcelDemy.



This post first appeared on ExcelDemy.com, please read the originial post: here

Share the post

How to Calculate Age in Excel from ID Number (4 Quick Methods)

×

Subscribe to Exceldemy.com

Get updates delivered right to your inbox!

Thank you for your subscription

×