VB.NET日期范围判断不起作用!解决方案
VB.NET日期范围判断不起作用!
nstrsql += " and (createddate>='" & TextBox3.Text & "' and createddate<='" & TextBox2.Text & "') "
我的日期值是:2007-12-27 14:20:22 2007-12-27:15:30:23
现在要取2007-12-27这一天的值, 结果按上面的做法却找不到记录,请问如何处理呢? 谢谢.
(注: 我的Createddate 是DateTime 型字段 )
------解决方案--------------------
Dim yyyy As String = Format(Date.Today, "yyyy")
Dim MM As String = Format(Date.Today, "MM")
Dim dd As String = Format(Date.Today, "dd")
Dim yyYear As Integer = Year("2007-12-28") '年份
Dim mh As Integer = Month("2007-12-28") '月份
Dim tDay As Integer = DateAndTime.Day("2007-12-28") '取日期 28日
'========================================================================
Dim gouriqi As String = "2007-12-31"
Dim GetDay As Integer = DateDiff("d", gouriqi, Date.Today)
If GetDay > 0 Then
'已过去的日期的天数
Else
'未来的日期的天数
End If
------解决方案--------------------
你需要的是Date,不是DateTime,你的查询语句不能查出2个日期间的数据,只能查出2个时间间的数据
如果数据库是DateTime类型,就用2007-12-18 00:00 和2007-12-18 23:59来查
------解决方案--------------------
datePart(year,Rq)=DatePart(year,yourRq) and DatePart(month,rq)=DatePart(month,yourRq) and DatePart(day,rq)=datePart(day,yourRq)
------解决方案--------------------
Dim BegDate As DateTime = CDate("2007-12-27")
Dim EndDate As DateTime = BegDate.AddDays(1).AddSeconds(-1)
nstrsql += "and createddate Between '" & BegDate & "' And '" & EndDate & "'"
------解决方案--------------------
nstrsql += " and (createddate> ='" & datevalue(TextBox3.Text) & "' and createddate <='" & datevalue(TextBox2.Text) & "') "
nstrsql += " and (createddate>='" & TextBox3.Text & "' and createddate<='" & TextBox2.Text & "') "
我的日期值是:2007-12-27 14:20:22 2007-12-27:15:30:23
现在要取2007-12-27这一天的值, 结果按上面的做法却找不到记录,请问如何处理呢? 谢谢.
(注: 我的Createddate 是DateTime 型字段 )
------解决方案--------------------
Dim yyyy As String = Format(Date.Today, "yyyy")
Dim MM As String = Format(Date.Today, "MM")
Dim dd As String = Format(Date.Today, "dd")
Dim yyYear As Integer = Year("2007-12-28") '年份
Dim mh As Integer = Month("2007-12-28") '月份
Dim tDay As Integer = DateAndTime.Day("2007-12-28") '取日期 28日
'========================================================================
Dim gouriqi As String = "2007-12-31"
Dim GetDay As Integer = DateDiff("d", gouriqi, Date.Today)
If GetDay > 0 Then
'已过去的日期的天数
Else
'未来的日期的天数
End If
------解决方案--------------------
你需要的是Date,不是DateTime,你的查询语句不能查出2个日期间的数据,只能查出2个时间间的数据
如果数据库是DateTime类型,就用2007-12-18 00:00 和2007-12-18 23:59来查
------解决方案--------------------
datePart(year,Rq)=DatePart(year,yourRq) and DatePart(month,rq)=DatePart(month,yourRq) and DatePart(day,rq)=datePart(day,yourRq)
------解决方案--------------------
Dim BegDate As DateTime = CDate("2007-12-27")
Dim EndDate As DateTime = BegDate.AddDays(1).AddSeconds(-1)
nstrsql += "and createddate Between '" & BegDate & "' And '" & EndDate & "'"
------解决方案--------------------
nstrsql += " and (createddate> ='" & datevalue(TextBox3.Text) & "' and createddate <='" & datevalue(TextBox2.Text) & "') "