How would you calculate the age in C# using date of birth (considering leap years)

前端 未结 6 1867
傲寒
傲寒 2020-12-21 07:02

Here is a problem. I have seen many solutions, but no one seems to be fulfilling the criteria I want...

I want to display the age in this format

20 y         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 07:34

    Check this code:

    {                                                    
        dif = int(datediff("D", Convert.ToDateTime("01/" + Q101m.text + "/" + Q101y.Text), (Convert.ToDateTime(Vdate.text)))/365.25)
    
        //If dif < 15 Or dif > 49 
        {
               MessageBox.Show("xxxxxxx");
               Q101m.Focus();
        }
    
    }
    

提交回复
热议问题