Vb.net 将日期时间限制为10年前

Vb.net 将日期时间限制为10年前,vb.net,date,datetime,Vb.net,Date,Datetime,我想将结果限制为只包括日期之间的记录表单。现在一直到10年前 我该怎么做 strWhere = WhereAction_DueAfterDate(Date.Now - 10 years) strWhere &= " And" & WhereAction_DueBeforeDate(Date.Now) 在DateTime类中使用AddYears: DateTime now As DateTime = DateTime.Now strWhere = WhereAction_Du

我想将结果限制为只包括
日期之间的记录表单。现在一直到10年前

我该怎么做

 strWhere = WhereAction_DueAfterDate(Date.Now - 10 years)
 strWhere &= " And" & WhereAction_DueBeforeDate(Date.Now)

DateTime
类中使用
AddYears

DateTime now As DateTime = DateTime.Now
strWhere = WhereAction_DueAfterDate(now.AddYears(-10))
strWhere &= " And" & WhereAction_DueBeforeDate(now)
它允许您通过放置
-
符号,立即修改
日期时间

旁注:声明您的
DateTime。现在
一次,然后再进一步处理它。这只是为了避免在
DateTime的第一次调用和第二次调用之间可能发生的时间差。现在如果我们不这样做,请执行以下操作:

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

DateTime
类中使用
AddYears

DateTime now As DateTime = DateTime.Now
strWhere = WhereAction_DueAfterDate(now.AddYears(-10))
strWhere &= " And" & WhereAction_DueBeforeDate(now)
它允许您通过放置
-
符号,立即修改
日期时间

旁注:声明您的
DateTime。现在
一次,然后再进一步处理它。这只是为了避免在
DateTime的第一次调用和第二次调用之间可能发生的时间差。现在如果我们不这样做,请执行以下操作:

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
您可以使用方法来完成该操作

strWhere = WhereAction_DueAfterDate(DateTime.Now.AddYears(-10))
希望要求是执行查询,如果是这样,您可以使用:

Datecolumn >= DATE_SUB(NOW(),INTERVAL 10 YEAR) // for mysql
您可以使用方法来完成该操作

strWhere = WhereAction_DueAfterDate(DateTime.Now.AddYears(-10))
希望要求是执行查询,如果是这样,您可以使用:

Datecolumn >= DATE_SUB(NOW(),INTERVAL 10 YEAR) // for mysql

你想在哪里应用limitI编辑了代码看你是否理解现在你想在哪里应用limitI编辑了代码看你是否理解now@AndreSmith太好了!:)只需声明
DateTime.Now
一次,如果您多次使用它(请参阅我的更新答案)。这是为了避免在不这样做的情况下出现微小的时差,但要调用
DateTimecode@AndreSmith太好了!:)只需声明
DateTime.Now
一次,如果您多次使用它(请参阅我的更新答案)。这是为了避免在不这样做时出现微小的时差,但要像在原始代码中一样多次调用
DateTime