计算出生日期的当前年龄 [英] calculate current age from date of birth

查看:83
本文介绍了计算出生日期的当前年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请帮帮我



如何计算出生日期和日期的当前年龄(日,月,年)出生时选择组合框?

i有三个组合框和一个文本框,第一个选择日期第二个选择月份,最后一个选择年份。在文本框中找到当前年龄(日,月,年)。

解决方案

嗨!!!你喜欢这样!!!



<前lang =c#> 受保护 void btn_Click( object sender,EventArgs e)
{
// 在这里你使用你的ddl,combobox等插入年龄日期
DateTime dtStart = DateTime.Parse(txtDoB.Text );
TimeSpan sp = DateTime.Now - dtStart;
int year = 18;
int days = 365 ;
int total = year * days;

if (sp.Days < total)
{

txtDoB.Text = 无效;
lblMess.Text = 你不能低于18岁;
lblMess.CssClass = Errr;
return ;
}
}





它唯一的基本想法是怎么做!!!!你在VB.net中使用c#中的代码我认为它应该可以帮助你!!!!!!


 受保护  Sub  btn_Click(发件人作为 对象,e  As  EventArgs)
' 在这里使用插入年龄日期的ddl,combobox等
Dim dtStart As DateTime = DateTime.Parse(txtDoB.Text)
Dim sp As TimeSpan = DateTime.Now - dtStart
Dim year As 整数 = 18
昏暗作为 整数 = 365
Dim total As 整数 =年*天

如果 sp.Days<总计然后

txtDoB.Text = 无效
lblMess.Text = 您不能低于18岁
返回
结束 如果
结束 Sub

< br $> b $ b

希望我帮助你。


试试这个:

  Dim  strDOB  As   String  
strDOB = txtDateOfBirth.TextDim
intAge As Integer
intAge = Math.Floor( DateDiff(DateInterval.Month,DateValue(strDOB),Now())/ 12
lblAge.Text = intAge


hi,
Please help me

how to calculate current age (Day, Month, Year) from date of birth and date of birth select from combo box?
i have three combo box and one text box first for select date second for select month and last for select year. find the current age with (Day, Month, Year) in text box.

解决方案

Hi!!! you do like that!!!

protected void btn_Click(object sender, EventArgs e)
    {
         // here you use your ddl,combobox or etc where age date is inserted
        DateTime dtStart = DateTime.Parse(txtDoB.Text);
        TimeSpan sp = DateTime.Now - dtStart;
        int year = "18";
        int days = 365;
        int total = year * days;

        if (sp.Days < total)
        {

            txtDoB.Text = "Not Valid";
            lblMess.Text = "You can not be under 18 years";
            lblMess.CssClass = "Errr";
            return;
        }
}



its only basic idea of how to do !!!! have code in c# you do in VB.net i think it should help you!!!!!!


Protected Sub btn_Click(sender As Object, e As EventArgs)
    ' here you use your ddl,combobox or etc where age date is inserted
    Dim dtStart As DateTime = DateTime.Parse(txtDoB.Text)
    Dim sp As TimeSpan = DateTime.Now - dtStart
    Dim year As Integer = "18"
    Dim days As Integer = 365
    Dim total As Integer = year * days

    If sp.Days < total Then

        txtDoB.Text = "Not Valid"
        lblMess.Text = "You can not be under 18 years"
        Return
    End If
End Sub



Hope I help you.


Try this:

Dim strDOB As String
strDOB = txtDateOfBirth.TextDim 
intAge As Integer
intAge = Math.Floor(DateDiff(DateInterval.Month, DateValue(strDOB), Now()) / 12)
lblAge.Text = intAge


这篇关于计算出生日期的当前年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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