C#
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.


Satya KarkiRank #78 · 24.6K reputationPosted Jun 11, 2021, 7:01 AM EDT
Satya KarkiRank #78 · 24.6K reputationPosted Jun 11, 2021, 7:31 AM EDT
Satya KarkiRank #78 · 24.6K reputationPosted Jun 11, 2021, 7:33 AM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Jun 11, 2021, 7:42 AM EDT
Bhavesh VankarRank #1,147 · 1.6K reputationPosted Jun 11, 2021, 7:02 AM EDT
Bhavesh VankarRank #1,147 · 1.6K reputationPosted Jun 11, 2021, 7:04 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jun 11, 2021, 7:15 AM EDT
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.
Pranam BhatRank #500 · 4.9K reputationPosted Jun 11, 2021, 7:16 AM EDT
Calculate Age from Date of Birth
Bhavesh VankarRank #1,147 · 1.6K reputationPosted Jun 11, 2021, 7:38 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jun 11, 2021, 7:40 AM EDT
Bhavesh VankarRank #1,147 · 1.6K reputationPosted Jun 11, 2021, 8:00 AM EDT
Amit PadhiyarRank #3,247 · 441 reputationPosted Jun 15, 2021, 8:34 AM EDT
This answer from: https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-based-on-a-datetime-type-birthday