DOB从日历中选择并自动计算AGE [英] DOB select from calender and auto calculate AGE

查看:168
本文介绍了DOB从日历中选择并自动计算AGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在DOB上选择并自动在文本框中生成他的AGE ...

i want to select on DOB and automatically generates his AGE in textbox...

推荐答案

DateTime dt = Calendar1.SelectedDate;
       DateTime dt1 = Convert.ToDateTime(DateTime.Now.ToShortDateString());
       TimeSpan t = dt1.Subtract(dt);
       TextBox1.Text = t.TotalDays.ToString();
       TextBox2.Text = (t.Days / 365).ToString();


尝试

如何使用C#中的DateTime计算年龄
[ ^ ]。


// birthdate
        DateTime birthdate = new DateTime(1989, 1, 1);
        TimeSpan dur = DateTime.Now.Subtract(birthdate);

        int noOfdays = dur.Days;

        int noYear = noOfdays / 365;
        int noMonth = noOfdays % 365 / 30;
        int days = noOfdays % 365 % 30;

        //result
        string Info = noYear + " years " + noMonth+ " month "+days+" days";


这篇关于DOB从日历中选择并自动计算AGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆