Bhavesh Vankar

Bhavesh Vankar

  • 725
  • 1.1k
  • 78.6k

How to find age using birthdate...

Jun 11 2021 10:41 AM
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.


Answers (12)