protected void txtdob_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(this.con2);
SqlCommand cmd = new SqlCommand("Select DATEDIFF(YEAR, CONVERT(datetime,'"+ txtdob.Text+"', 103),CONVERT(datetime, V_ISSUEDATE, 103)) FROM STUDENTRECORD");
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DateTime obj = new DateTime();
ds.Tables[0].Rows[i]["V_BIRTHDATE"].ToString();
}
}
i want to find age using server's current date. how to do it.
if user enter birth date in textbox 1 then age should be display in Textbox 2 when user focus out from textbox 1.
but current date should be consider from server like sql server. i have try as below but what to do having no proper idea.

Amit PadhiyarPosted Jun 15, 2021, 12:34 PM
This answer from: https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-based-on-a-datetime-type-birthday
Bhavesh VankarPosted Jun 11, 2021, 12:00 PM
Rijwan AnsariPosted Jun 11, 2021, 11:42 AM
Sachin SinghPosted Jun 11, 2021, 11:40 AM
Bhavesh VankarPosted Jun 11, 2021, 11:38 AM
Satya KarkiPosted Jun 11, 2021, 11:33 AM
Satya KarkiPosted Jun 11, 2021, 11:31 AM
Pranam BhatPosted Jun 11, 2021, 11:16 AM
Calculate Age from Date of Birth
Sachin SinghPosted Jun 11, 2021, 11:15 AM
step 1. create a function in SQL server, so that you could use the same logic multiple times.
step 2. Call this function using the command, also why do you need a loop, i guess each student have a different V_IssueDate as the current date, so retrieve it on the basis of student Name/ courseName/Job Name.
Bhavesh VankarPosted Jun 11, 2021, 11:04 AM
Bhavesh VankarPosted Jun 11, 2021, 11:02 AM
Satya KarkiPosted Jun 11, 2021, 11:01 AM