在SQL select查询中使用当前日期时间检查两个日期时间 [英] Check two datetime with current datetime in SQL select query

查看:628
本文介绍了在SQL select查询中使用当前日期时间检查两个日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要在sql select Query中检查当前日期时间的两个日期时间字段。



这里我有两个字段From_date,To_date DATATYPE日期时间。我需要使用当前系统日期时间检查此字段。



注意:

我需要搜索日期和时间。



我尝试过:



选择c.Offername作为定义,Offerid作为stockid, CAST('0'作为货币)

为Available_QTY,c.categoryid来自tbloffer为c其中

from_time> = getdate()和to_time< = getdate()

Hi to all,
I need To check TWo Datetime Field wiht current datetime in sql select Query.

Here i have Two Fields From_date, To_date DATATYPE datetime. I need To check This Field With current system Datetime.

NOTe:
I need to search DATE And TIME.

What I have tried:

select c.Offername as Definition,Offerid as stockid,CAST('0' AS MONEY)
as Available_QTY,c.categoryid from tbloffer as c where
from_time >= getdate() and to_time<=getdate()

推荐答案

一般来说,from_datetime应该在to_datetime之前,你的代码就是这样:

In common sense, from_datetime should be before to_datetime, your code defies this:
from_time >= getdate() and to_time<=getdate()



重新审视你的逻辑。

事实上,你可以这样做:


re-examine your logic.
In fact, you can simply do this:

SELECT * FROM tablename WHERE getdate() BETWEEN from_datetime AND to_datetime


这篇关于在SQL select查询中使用当前日期时间检查两个日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆