office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

微信交流群(請(qǐng)用微信掃碼)

        

Access以半周歲為單位計(jì)算年齡

2018-10-16 17:29:00
tmtony8
原創(chuàng)
6250

一般情況下,我們習(xí)慣說年齡都要虛歲為主。不滿周歲會(huì)直接算成周歲。這個(gè)計(jì)算很簡單,直接用當(dāng)前年份-出生年份(year(Data())-year(出生))即可。

但是小孩子變化很快,每半周歲情況就會(huì)有大不同,所以需要以半周歲為一個(gè)單位。

如出生在2008-4-6,今天是2018-10-16 ,即合計(jì)是10年6個(gè)月1天。所以已經(jīng)是10.5歲了。


詳細(xì)代碼:

    Dim sngAge As Single
    Dim intYear As Integer
    Dim intMonth As Integer


    If Month(Me.Text1) = Month(Date) Then
        If Day(Me.Text1) <= Day(Date) Then
            
            intYear = Year(Date) - Year(Me.Text1)
            intMonth = Month(Date) - Month(Me.Text1)
        Else
            intYear = Year(Date) - Year(Me.Text1) - 1
            intMonth = Month(Date) + 12 - Month(Me.Text1)
            
        End If
    ElseIf Month(Me.Text1) > Month(Date) Then
        intYear = Year(Date) - Year(Me.Text1) - 1
        intMonth = Month(Date) + 12 - Month(Me.Text1)
        
    Else
        intYear = Year(Date) - Year(Me.Text1)
        If Day(Me.Text1) <= Day(Date) Then
            intMonth = Month(Date) - Month(Me.Text1)
        Else
            intMonth = Month(Date) - Month(Me.Text1) - 1
            
        End If
    End If
    
    If intMonth >= 6 Then
        
        
        sngAge = intYear + 0.5
    Else
        sngAge = intYear
    End If
    
    
    Me.Text10 = "我年齡是 " & sngAge & "歲"


同理出生在2009-10-15,今天是2018-10-16 ,9年多一天,所以已經(jīng)是9歲了。

    分享
    文章分類
    聯(lián)系我們
    聯(lián)系人: 王先生
    Email: 18449932@qq.com
    QQ: 18449932
    微博: officecn01
    移動(dòng)訪問