简体   繁体   English

VB.net-CDate与SQL

[英]VB.net - CDate with SQL

I'm doing the following query to check if the current month is the same as the SQL field "Start". 我正在执行以下查询,以检查当前月份是否与SQL字段“开始”相同。

If Today.Month = CDate(rsData("Start")).Month Then

What I'd like to do is switch it so that it will check within a 30 day period rather than identify the current month? 我想做的就是切换它,以便它将在30天之内检查而不是确定当前月份? Any ideas on how to do this? 有关如何执行此操作的任何想法?

If Date.Today.AddDays(-30) >= CDate(rsData("Start"))
 ' start date not older than 30 days '
End If

or if you have a variable date: 或者您的日期可变:

var minBoundary = New Date(2011,1,1)
var maxBoundary = New Date(2012,1,1)
var startDate = CDate(rsData("Start"))

If startDate  >= MinBoundary AndAlso startDate <= maxBoundary 
 ' start date between two dates '
End If

I believe in this case you would want to use the AddDays method of DateTime. 我相信在这种情况下,您将要使用DateTime的AddDays方法。

Dim mydate as DateTime = CDate(rsData("Start"))
Dim checkdate as DateTime = mydate.AddDays(30)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM