帮助里面有一段“本月生日员工”的查询代码,打算修改成“一年内退休人员”,退休时间已知,对最长那一句始终未吃透,新手啊,求指点。
最好给分析一下“If (dt1 >= Date.Today AndAlso dt1 < Date.Today.AddYears(n)) OrElse (dt2 >= Date.Today AndAlso dt2 < Date.Today.AddDays(n)) ”这句,对时间段很头大。
Dim ids As String
Dim n As Integer = 1 '一年内
For Each dr As DataRow In DataTables("基本信息").DataRows
Dim dt As Date = dr("退休时间")
Dim dt1 As New
Date(Date.Today.Year,dt.Month,dt.Day)
Dim dt2 As New
Date(Date.Today.AddYears(n).Year,dt.Month,dt.Day)
Dim t As TimeSpan = dt2 - dt1
If (dt1 >= Date.Today AndAlso dt1 < Date.Today.AddYears(n)) OrElse
(dt2 >= Date.Today AndAlso dt2 < Date.Today.AddDays(n)) Then
ids = ids & ",'"
& dr("工号")
& "'"
End If
Next
If ids > "" Then
ids = ids.Trim(",")
Tables("基本信息").filter
= "[工号] In
(" & ids &")"
End If
Forms("正式工信息").Open
MainTable = Tables("基本信息")