Age in years with decimal precision given a datetime

前端 未结 6 1919
-上瘾入骨i
-上瘾入骨i 2021-01-06 03:37

How can I get the age of someone given the date of birth in a C# datetime.

I want a precise age like 40.69 years old

6条回答
  •  借酒劲吻你
    2021-01-06 04:08

    An approximite would be:

            DateTime bd = new DateTime(1999, 1, 2);
    
            TimeSpan age = DateTime.Now.Subtract(bd);
            Console.WriteLine(age.TotalDays / 365.25);
    

提交回复
热议问题