我希望将结果限制为仅包括{10}之前Date.Now
之间的记录形式。
我该怎么做?
strWhere = WhereAction_DueAfterDate(Date.Now - 10 years)
strWhere &= " And" & WhereAction_DueBeforeDate(Date.Now)
答案 0 :(得分:4)
在DateTime
课程中使用DateTime now As DateTime = DateTime.Now
strWhere = WhereAction_DueAfterDate(now.AddYears(-10))
strWhere &= " And" & WhereAction_DueBeforeDate(now)
:
Now
它允许您通过添加DateTime
符号来修改-
DateTime.Now
。
附注:在进一步处理之前,声明您的DateTime.Now
一次。这只是为了避免在第一次通话和第二次通话strWhere = WhereAction_DueAfterDate(DateTime.Now.AddYears(-10))
strWhere &= " And" & WhereAction_DueBeforeDate(DateTime.Now) 'There is a little difference between the first and the second DateTime Now
之间可能发生的时间差异,如果我们不这样做的话:
1112 1232 1233 1233 1232 1111 0000
1111 1111 0000 1211 0001 1110 1212
1212 1111 1111 1111 1111 1111 1111
1111 1111 1111 1111 1111 1111 1111
20 121 12 50 12 11 9
答案 1 :(得分:1)
您可以使用AddYears()
方法完成操作。
strWhere = WhereAction_DueAfterDate(DateTime.Now.AddYears(-10))
希望要求是执行查询,如果是,您可以使用:
Datecolumn >= DATE_SUB(NOW(),INTERVAL 10 YEAR) // for mysql