Age in years with decimal precision given a datetime

前端 未结 6 1917
-上瘾入骨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:11

    You could do this:

    Console.WriteLine(DateTime.Now.Date.Subtract(new DateTime(1980, 8, 1)).TotalDays / 365.25);
    

提交回复
热议问题