急!急!急!请教datetime问题!

bibibi 2000-08-28 03:05:00
想查date1至date2的记录写成:
year1=Cint(request.form("year1"))
mon1=Cint(request.form("mon1"))
year2=Cint(request.form("year2"))
mon2=Cint(request.form("mon2"))
date1=FormatDateTime(DateSerial(year1,mon1,1))
date2=FormatDateTime(DateSerial(year2,mon2,30))
set con=application("Cn")
set rs=server.createobject("adodb.recordset")
sql="Select Content,Subject from DocumentInfo where IssueTime between '"&date1&"' and '"&date2&"'"
rs.open sql,con
显示出错:
Microsoft OLE DB Provider for SQL Server error '80040e07'

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
到底该怎么写?请指教!



...全文
127 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
DarkNight 2000-08-31
  • 打赏
  • 举报
回复
日期应该用#号括起来:sql="Select Content,Subject from DocumentInfo where IssueTime between #"&date1&"# and #"&date2&"#"
hhzh426 2000-08-30
  • 打赏
  • 举报
回复
date1=request.form("year1") & "-" & request.form("mon1") & "-1"
date2=request.form("year2") & "-" & request.form("mon2") & "-1"
date2=dateadd("m",1,date2)
mysql="Select Content,Subject from DocumentInfo where IssueTime between '" & date1 & "' and '" & date2 & "'"
第三行语句是将用户选择的月份增加1,因为sql表示的时间是yyyy-mm-dd hh:mm:ss.xxx
如果只是输入日期的话自动设为0时0分0.000秒,因此在第二个日期上加上一个月正巧可以将选
定的年份和月份之间的数据全部包括在内!
huntout 2000-08-28
  • 打赏
  • 举报
回复
二月沒有30日呀!︰)

year1=Cint(request.form("year1"))
mon1=Cint(request.form("mon1"))
year2=Cint(request.form("year2"))
mon2=Cint(request.form("mon2"))
set con=application("Cn")
set rs=server.createobject("adodb.recordset")
sql="Select Content,Subject from DocumentInfo where datepart(yyyy, IssueTime) between " & year1 & " and " & year2 & " and datepart(m, IssueTime) between " & mon1 & " and " & mon2
rs.open sql,con

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧