VBScript 和 SQL Server - 使用 SQL 比较两个日期时间

发布于 2024-11-03 01:10:23 字数 338 浏览 0 评论 0原文

我试图选择 DateTimeEntered 距离变量 MyDateTime 大约 4 小时以内的所有记录。有什么想法如何做到这一点?这是我正在尝试的方法,但由于一些明显的原因,它不起作用。显然,转换为双倍不是一种选择。另外,我只是检查 MyDateTime 的值是否小于 0.1,但我还需要检查它是否大于但不大于 0.1。我猜有更好的方法可以做到这一点。有什么想法吗?

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

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 not 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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不吻晚风 2024-11-10 01:10:23

经典 ASP 中的 VBA 可能会类似于

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

基本上会执行此操作(具有 MyDateTime 的值)

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文