Click here to Skip to main content
15,070,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i calculate the age of user when he selects a age in calendar control. i want this to done when button is clicked.I used a txtbox and below it a calendar control. how can i do this without using ajax.Suppose when user selects 2/12/1987 then in database automatically age=26 yr should be submiteed.Thnks.
Posted
Comments
_Damian S_ 18-Jun-13 2:35am
   
Why do you want to store the persons age in the database rather than their date of birth?
Rambo_Raja 18-Jun-13 2:39am
   
ah ;) i know that its not good to keep age in DB but i just want this only to be done..
Member 10721202 10-Apr-14 16:08pm
   
he how to date calaulation after age see

1 solution

Age is a little more complex than you might think! See here: Working with Age: it's not the same as a TimeSpan![^]
   
Comments
Rambo_Raja 18-Jun-13 3:01am
   
hi!...can i use javascript to get age...?
Rambo_Raja 18-Jun-13 3:04am
   
code in javascript is as: function ageCount() {
var date1 = new Date();
var dob= document.getElementById("dob").value;
var date2=new Date(dob);
var pattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Regex to validate date format (dd/mm/yyyy)
if (pattern.test(dob)) {
var y1 = date1.getFullYear(); //getting current year
var y2 = date2.getFullYear(); //getting dob year
var age = y1 - y2; //calculating age
document.write("Age : " + age);
return true;
} else {
alert("Invalid date format. Please Input in (dd/mm/yyyy) format!");
return false;
}
OriginalGriff 18-Jun-13 3:17am
   
You can do it in JS, but you would need code very similar to that in the C# link I gave you.

BTW: If you want a JavaScript solution in future, you should put that in your question rather than C#...
Member 13975474 1-Jan-21 1:57am
   
Is Dob a textbox or asp calendar?
Rambo_Raja 18-Jun-13 3:24am
   
okes..thnx

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900