开发者

VBScript and SQL Server - Compare Two datetimes Approximately Using SQL

I'm trying to select all records where DateTimeEntered is within roughly 4 hours of variable MyDateTime. Any ideas how to do this? Here's what I was trying and it doesn't work for some obvious reasons. Apparently casting to double is not an option. Also, I'm only checking to see if the value of MyDateTime is less by less than .1 but I also need to check to see if it's greater but n开发者_高级运维ot greater than .1. I'm guessing there is a better way of doing this. Any ideas?

"SELECT ID from visit " & _
    "WHERE (Cast(datetimeentered AS Double) - " & CDbl(MyDateTime) & ") < .1"


The VBA in your Classic ASP may turn out to be something like

strVisits = strVisits & " Select * from Visit" & vbcrlf
strVisits = strVisits & " Where DateTimeEntered Between  DateAdd (hour, '" & MyDateTime& "', -2) "  & vbcrlf
strVisits = strVisits & " and DateAdd (hour, '" & MyDateTime& "', 2)"

That will basically do this (with the value of MyDateTime)

Select *
from Visit
Where DateTimeEntered Between  DateAdd (hour, MyDateTime, -2) and DateAdd (hour, MyDateTime, 2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜