11,719,185 members (87,624 online)
Rate this:
See more:
Hi All,

How to calculate age based on "date time picker selection" in windows application with c# coding.

Thanks and Regards,
Murali.
Posted 30-Dec-12 23:53pm
Edited 30-Dec-12 23:59pm
v2

Rate this:

Solution 3

```int myAge =
DateTime.Today.Year - dateTimePicker1.Value.Year; // CurrentYear - YourBirthDate

textBox1.Text = myAge.ToString();
```
v3
ProgramFOX at 31-Dec-12 6:49am

I'm not sure about this. If 'Today' is 30 Dec 2012, and if your birth date is 31 Dec 2011, then your output will be '1'. But that's not correct, because '1' is only correct from 31 Dec 2012 up to and including 30 Dec 2013.
Rate this:

Solution 1

Hi,

Have a look here:
Calculating Duration Between Two Dates in Years, Months and Days[^]
To get the value (`DateTime`) from `DateTimePicker`, try this:
```DateTime dt = dateTimePicker1.Value;
```
v2
Rate this:

Solution 2

Try this..

```TimeSpan ts=DateTime.Now - Convert.ToDateTime(datePicker.SelectedDate);
int age = Convert.ToInt32(ts.Days) / 365;```

hope this will heip you.
Rate this:

Solution 5

Is there a whole small sample program on this? Thanks in advance...
Rate this:

Solution 6

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim iMonths As Integer
Dim iYears As Integer
Dim iDays As Integer
iYears = Now.Year - DateTimePicker1.Value.Year
iMonths = Now.Month - DateTimePicker1.Value.Month
iDays = Now.Day - DateTimePicker1.Value.Day

If iMonths + 12 < 12 Then
iYears = Years - 1
iMonths = 12 + Months
iDays = 30 + Days
End If

TextBox1.Text = iYears & " Years " & iMonths & "Months" & iDays & "Days"
End Sub
CHill60 at 21-Jul-15 6:28am

Firstly, this post was resolved over 2 years ago, and was tagged C# not VB so your response is "Off Topic"
Secondly, it won't even compile (iYears not Years, iMonths not Months and iDays not Days), so your response is "Unclear or Incomplete"
I suggest you remove it to avoid down-votes and reports