---
title: "Calculate Age in ASP.Net C#"  
description: "Some time we face problem related to calculating exact age in year. In this blog I have explained how to calculate exact age in year in ASP.Net with C"  
author: "AVADHESH PATEL"  
published: 2013-04-01  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/473/calculate-age-in-asp-dot-net-c-sharp  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Calculate Age in ASP.Net C#

Some time we face problem related to calculating exact age in year. In this blog I have explained how to calculate exact age in year in [ASP.Net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) with C#.For demonstration, take one [TextBox](https://www.mindstick.com/articles/320/textbox-control-in-vb-dot-net) (TextBox1), one Button (Button1) and one Label (Label1) control on your [ASPX page](https://www.mindstick.com/forum/218/how-do-i-create-an-aspx-page-that-periodically-refreshes-itself). Now generate Button’s [Click event](https://www.mindstick.com/forum/424/how-to-call-form_paint-event-on-button-click-event) (Button1_Click ()) and write below line of code.

```
// Get current date timeDateTime d = DateTime.Now;// Changed MM/dd/yyyy format to dd/MM/yyyy fromatstring s = d.ToString("dd/MM/yyyy");// Convert date time in string (s) to DateTime (Todate) data typeDateTime Todate = DateTime.Parse(s, CultureInfo.CreateSpecificCulture("en-IA"));// Convert entered date string (TextBox1.Text) to DateTime (givenDate) Data TypeDateTime givenDate = DateTime.Parse(TextBox1.Text);// Count total daysdouble days = Todate.Subtract(givenDate).Days;// Convert days to year and display into Label.TextLabel1.Text = Math.Floor(days / 365.24219).ToString();
```

##### Note:

1. If you want to used Global [DateTime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) format then replay below line from

given line

DateTime d = DateTime.Now;

To

DateTime d = DateTime.UtcNow;

DateTime.UtcNow tells you the date and time as it would be in

Coordinated [Universal](https://answers.mindstick.com/qa/101376/who-s-the-current-wwe-universal-champion) Time, which is also called the Greenwich Mean Time

time zone

DateTime.Now gives the date and time as it would appear to someone in

your current locale.

2. Here I have given DateTime [culture](https://www.mindstick.com/articles/44200/5-ways-to-improve-the-company-culture) is “en-IA”. Change culture

according your required.

```
DateTime Todate = DateTime.Parse(s, CultureInfo.CreateSpecificCulture("en-IA"));
```

##### Culture Description

en-AU (English [Australia](https://www.mindstick.com/articles/12829/aspects-that-make-australia-post-shipping-extension-a-useful-tool)): 24/10/2011

en-IA (English India): 24-10-2011

en-ZA (English [South Africa](https://www.mindstick.com/articles/198627/south-africa-vs-italy-rwc-2019-what-when-how-to-follow-the-match)): 2011/10/24

en-US (English [United States](https://www.mindstick.com/news/2228/the-united-states-claims-seagate-broke-export-laws-by-selling-huawei-hard-drives)): 10/24/2011

---

Original Source: https://www.mindstick.com/blog/473/calculate-age-in-asp-dot-net-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
