---
title: "SQL Query to Calculate Age from Date of Birth in SQL Server"  
description: "SQL Query to Calculate Age from Date of Birth in SQL Server"  
author: "Anubhav Sharma"  
published: 2024-07-15  
updated: 2024-07-16  
canonical: https://www.mindstick.com/forum/160919/sql-query-to-calculate-age-from-date-of-birth-in-sql-server  
category: "SQL Server"  
tags: ["database", "sql server", "sql server 2008"]  
reading_time: 2 minutes  

---

# SQL Query to Calculate Age from Date of Birth in SQL Server

Hello,

I need a [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) to calculate the [age](https://www.mindstick.com/articles/23262/the-modern-age-these-technology-trends-can-make-your-life-easier) of [employees](https://www.mindstick.com/articles/44463/business-to-business-vat-reclaiming-a-guide-for-your-employees) from their `DateOfBirth` [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) in the `Employee` table. How can I do this in SQL Server?

## Replies

### Reply by Ravi Vishwakarma

To calculate age from date of birth in SQL Server, you can use the `DATEDIFF` function along with `GETDATE()` to get the current date.

Here's an example query:

## Example 1

```plaintext
SELECT
    UserID,
    DateOfBirth,
    DATEDIFF(YEAR, DateOfBirth, GETDATE()) AS Age
FROM Users;
```

**DATEDIFF(YEAR, DateOfBirth, GETDATE())**: Calculates the difference in years between the

current date (`GETDATE()`) and the `DateOfBirth`.

## Example 2

```plaintext
-- Assuming you have a table named 'Users' with columns 'UserID' and 'DateOfBirth'
SELECT
    UserID,
    DateOfBirth,
    DATEDIFF(YEAR, DateOfBirth, GETDATE()) -
        CASE
            WHEN DATEADD(YEAR, DATEDIFF(YEAR, DateOfBirth, GETDATE()), DateOfBirth) > GETDATE()
                THEN 1
            ELSE 0
        END AS Age
FROM Users;
```

**CASE ... END**: Adjusts the age if the birth date for this year hasn't occurred yet. It subtracts 1 from the age if the birthday hasn't occurred in the current year.

This query assumes you have a table named `Users` with columns `UserID` and `DateOfBirth`. Adjust the table and column names as per your database schema.

[**How do I use CTE to simplify complex queries in SQL Server?**](https://www.mindstick.com/blog/304466/how-do-i-use-cte-to-simplify-complex-queries-in-sql-server)

[**Explain the Aggregate functions in the SQL server.**](https://www.mindstick.com/blog/304494/explain-the-aggregate-functions-in-the-sql-server)

[**Explain the transaction in SQL Server.**](https://www.mindstick.com/blog/304493/explain-the-transaction-in-sql-server)

[**MERGE statement in SQL Server to perform upserts**](https://www.mindstick.com/blog/304491/merge-statement-in-sql-server-to-perform-upserts-update-inserts)


---

Original Source: https://www.mindstick.com/forum/160919/sql-query-to-calculate-age-from-date-of-birth-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
