如何在 vb.net 中按年龄过滤

how to filter by age in vb.net

我需要添加一个过滤器来按年龄过滤数据。 下面是我用来过滤电话和 phone 号码的代码。

我的客户 collects/holds 出生日期是 "app.DOB"

请帮助我

Friend Overrides Function Filter() As String

            Dim sb As New StringBuilder()

            If (Not app.LandPhone.StartsWith("01")) And (Not app.LandPhone.StartsWith("02")) Then
                sb.Append("Land phone must be present and start 01 or 02;")
            End If

            If (Not app.WorkPhone.StartsWith("01")) And (Not app.WorkPhone.StartsWith("02")) And (Not app.WorkPhone.StartsWith("08")) Then
                sb.Append("Work phone must be present and start 01, 02 or 08;")
            End If

            If app.MobilePhone = String.Empty Then
                sb.Append("Mobile phone must be present;")
            End If


            Return sb.ToString()
        End Function

如果 DOb 是日期时间,那么 DateDiff 函数将是 usefull.it 就像

if DateDiff(DateInterval.day,app.DOB,Date.Today)/365 > your filter value
''what you want to do
end if

注: 现在只有我注意到你的评论是 string.i 这种情况在像

这样的 datediff 函数中使用之前使用 parseexact 将其转换为日期

如果您的 DOB 列的格式是 dd/MM/yyyy 那么

 Dim dt = DateTime.ParseExact(app.DOB, "dd/MM/yyyy", Nothing)
if DateDiff(DateInterval.day,dt,Date.Today)/365 > your filter value
'' what you want
end if

您可以根据您的网格格式更改格式: