以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]用身份证如何计算年龄  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=129989)

--  作者:liuchunlei429
--  发布时间:2019/1/10 11:47:00
--  [求助]用身份证如何计算年龄
表中有 了身份证列,如何自动计算年龄,表达式怎么写,求高手知
--  作者:有点甜
--  发布时间:2019/1/10 11:53:00
--  
datacolchanged事件

 

Select Case e.DataCol.Name
    Case "身份证号"
        If e.DataRow.IsNull("身份证号") Then  \'身份证号码是否为空
            e.DataRow("出生日期") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("性别") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("年龄") = Nothing \'如果为空,则清除年龄
        Else
            \'否则从身份证号码列中提取出生日期
            e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号"))
            e.DataRow("性别") = ReadSex(e.DataRow("身份证号"))
            Dim d As Date = ReadBirthday(e.DataRow("身份证号"))
            Dim y As Integer = d.year
            If format(d, "MMdd") <= Format(Date.Today, "MMdd") Then
                e.DataRow("年龄") = Date.Today.Year - y
            Else
                e.DataRow("年龄") = Date.Today.Year - y -1
            End If
        End If
End Select


--  作者:有点甜
--  发布时间:2019/1/10 11:53:00
--  

http://www.foxtable.com/webhelp/scr/1445.htm