尝试在两个日期之间执行sql语句时出错

Beg*_*ner 0 sql sql-server asp-classic

SQL:

dim sql
sSql = "SELECT * FROM [dbo].[table] WHERE [sent] = 1 and datesent between '" & dStartDate & "' and '"  & dFinishDate & "'"
response.write(sSql)
set oRs = oConn.execute(sSql)       
Run Code Online (Sandbox Code Playgroud)

当我在sql server 2008中执行此sql时,它工作正常.但是,当我在我的应用程序中执行它时,我得到错误:

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.
Run Code Online (Sandbox Code Playgroud)

我在应用程序中有什么不同的东西吗?谢谢

Mit*_*eat 5

您是否尝试过使用ISO格式的日期?

SELECT * FROM [dbo].[Table]  
WHERE [sent] = 1 and datesent between '20120101' and '20120127' 
Run Code Online (Sandbox Code Playgroud)

(严格来说,sql server 的ISO 8601日期yyyy-mm-ddThh:mm:ss[.mmm])

旁注:输出到文本(或有文字)时,始终使用ISO格式日期; 这样就可以在所有系统上明确地阅读它们.

SQL Server ISO 8601格式日期

http://msdn.microsoft.com/en-us/library/ms190977(v=sql.90).aspx