如何使用日历工具计算年龄

如何使用日历工具计算年龄

本文介绍了如何使用日历工具计算年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用日历工具计算年龄

how to calculate age by using calender tool

推荐答案

private void calendar1_onselectionchanged(object sender,EventArgs e)
{
 int age= (DateTime.Today.Year - calendar1.SelectedDate.Year) * 372 + (DateTime.Today.Month - calendar1.SelectedDate.Month) * 31 + (DateTime.Today.Day - calendar1.SelectedDate.Day)) / 372;
}


Private Sub deDOB_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles deDOB.EditValueChanged
        Dim years As Long

        Select Case Today.Month
            Case Is < deDOB.DateTime.Month
                years = DateDiff(DateInterval.Year, deDOB.DateTime, Today) - 1

            Case Is = deDOB.DateTime.Month
                Select Case Today.Day
                    Case Is < deDOB.DateTime.Day
                        years = DateDiff(DateInterval.Year, deDOB.DateTime, Today) - 1
                    Case Is = deDOB.DateTime.Day
                        years = DateDiff(DateInterval.Year, deDOB.DateTime, Today)
                    Case Is > deDOB.DateTime.Day
                        years = DateDiff(DateInterval.Year, deDOB.DateTime, Today)
                End Select
            Case Is > deDOB.DateTime.Month
                years = DateDiff(DateInterval.Year, deDOB.DateTime, Today)
        End Select

        txtAge.Text = years.ToString
    End Sub



这篇关于如何使用日历工具计算年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 19:00