Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

C# syntax from VB: Datediff("yyyy",sDoB,date()) ?

Mar 6 2003 7:27 PM
Hi, I would like to calculate the age of a person given his/her birthdate. I'm doing this in C# and I had a really hard time finding the similar function like how VBScript used to do: Datediff("yyyy",sDoB,date()) when "yyyy" will give you the number of years. In my code: DateTime date1 = new DateTime(1972,1,1); //let's say the person's birthdate is 1/1/1972 TimeSpan TimeAlive = DateTime.Now - date1; Response.Write (TimeAlive); So I want to calculate how old he/she is from today's date. But so far I can only get the number of days. Is there another way? Thank so much!

Answers (2)