选择大于或等于当前日期的记录 [英] Select records greater than or equal to current date

查看:169
本文介绍了选择大于或等于当前日期的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用sqlserver 2008
我有一个名为tbl1
的表 其中的列名称为eventDate,数据类型为datetime

现在,我想找出具有eventDate大于当前日期的记录.

我为其编写的查询如下所示:

I am using sqlserver 2008
I have a table named tbl1
in it a column name eventDate with datatype = datetime

Now i want to find out records having eventDate greater than equal to current date.

The query i wrote for it is as under

select * from tbl1 where eventDate>=GetDate()



但是这个查询给了我将来的记录.但不是当前日期

我已经解决了一个问题,即GetDate()函数还将比较时间部分和当前时间部分,而evenrDate的时间部分没有相等的值.那就是为什么我没有得到理想的结果.

那么如何获得期望的结果.



But this query gives me future records. but not of current date

I have figured out one problem that GetDate() function will also compare the time part and current time part and evenrDate''s time part doesnt have equal values. Thats why i m not getting desired result.

So how to get desired results.

推荐答案

您确定 eventDate大于等于当前日期 ??
如果是这样,请尝试以下
Are you sure eventDate greater than equal to current date ??
If so try the following
select * from tbl1 where LEFT(CONVERT(DATETIME,eventDate,103),12)>=LEFT(CONVERT(DATETIME,GetDate,103),12)



如果您要查找的eventDate小于当前日期,请尝试以下操作:



If you are looking for eventDate less than equal to current date, then try the followin:

select * from tbl1 where LEFT(CONVERT(DATETIME,eventDate,103),12)<=LEFT(CONVERT(DATETIME,GetDate,103),12)



请让我知道您的反馈意见.



Please let me know your feedback.


您需要尝试的尝试少于--
select * from tbl1 where eventDate<=GetDate
You need to try less than -
select * from tbl1 where eventDate<=GetDate


这篇关于选择大于或等于当前日期的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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