Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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: bad
good
Please Sign up or sign in to vote.

Solution 3

int myAge = 
DateTime.Today.Year - dateTimePicker1.Value.Year; // CurrentYear - YourBirthDate
 
 textBox1.Text = myAge.ToString();
  Permalink  
v3
Comments
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: bad
good
Please Sign up or sign in to vote.

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;
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this..
 
TimeSpan ts=DateTime.Now - Convert.ToDateTime(datePicker.SelectedDate);
int age = Convert.ToInt32(ts.Days) / 365;
 
hope this will heip you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 225
1 BillWoodruff 200
2 OriginalGriff 191
3 Kornfeld Eliyahu Peter 175
4 CPallini 164


Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 25 Feb 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100