各位老师,我要在{消费记录}表中查询30天内有购买的顾客,参照 帮助中 未来七天即将过生日 的代码:
Dim nms
As
String
Dim n As Integer = 6
'未来天数,含今天,所以实际是未来7天
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.AddDays(n).Year,dt.Month,dt.Day)
If (dt1 >= Date.Today
AndAlso dt1 <
Date.Today.AddDays(n)) OrElse (dt2 >=
Date.Today
AndAlso dt2 <
Date.Today.AddDays(n)) Then
nms
= nms & ",'" &
dr("姓名") &
"'"
End
If
Next
If nms > ""
Then
nms =
nms.Trim(",")
Tables("员工").filter = "[姓名] In (" & nms &")"
End
If
写成如下代码:
Dim nms As String
Dim n As Integer = -29 '未来天数,含今天,所以实际是未来7天
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.AddDays(n).Year,dt.Month,dt.Day)
If (dt1 <= Date.Today AndAlso dt1 > Date.Today.AddDays(n)) OrElse (dt2 <= Date.Today AndAlso dt2 > Date.Today.AddDays(n)) Then
nms = nms & ",'" & dr("VIP卡号") & "'"
End If
Next
If nms > "" Then
nms = nms.Trim(",")
Tables("消费记录").filter = "[VIP卡号] In (" & nms &")"
End If
但是没有实现,是不是哪里错了?
我知道一点是:生日的查询查到月和日,不管年份,而我这个查询要具体到年月日,但是不知道怎么写。。。