How would I show something in SQL where the date is greater than the current date?
如何在SQL中显示日期大于当前日期的内容?
I want to pull out data that shows everything greater from today (now) for the next coming 90 days.
我想提取数据,显示今天(现在)未来90天的所有内容。
I was thinking =< {fn NOW()}
but that doesnt seem to work in my sql view here.
我在想= <{fn NOW()},但这似乎不适用于我的sql视图。
How can this be done?
如何才能做到这一点?
7 个解决方案
#1
25
SELECT *
FROM MyTable
WHERE CreatedDate >= getdate()
AND CreatedDate <= dateadd(day, 90, getdate())
http://msdn.microsoft.com/en-us/library/ms186819.aspx
http://msdn.microsoft.com/en-us/library/ms186819.aspx
#2
4
Assuming you have a field for DateTime
, you could have your query look like this:
假设您有一个DateTime字段,您的查询可能如下所示:
SELECT *
FROM TABLE
WHERE DateTime > (GetDate() + 90)
#3
2
For those that want a nice conditional:
对于那些想要一个好条件的人:
DECLARE @MyDate DATETIME = 'some date in future' --example DateAdd(day,5,GetDate())
IF @MyDate < DATEADD(DAY,1,GETDATE())
BEGIN
PRINT 'Date NOT greater than today...'
END
ELSE
BEGIN
PRINT 'Date greater than today...'
END
#4
1
In sql server, you can do
在sql server中,你可以做到
SELECT *
FROM table t
WHERE t.date > DATEADD(dd,90,now())
#5
1
For SQL Server
对于SQL Server
select *
from YourTable
where DateCol between getdate() and dateadd(d, 90, getdate())
#6
1
Select * from table where date > 'Today's date(mm/dd/yyyy)'
You can also add time in the single quotes(00:00:00AM)
您还可以在单引号中添加时间(00:00:00 AM)
For example:
例如:
Select * from Receipts where Sales_date > '08/28/2014 11:59:59PM'
#7
0
If you're using SQL Server it would be something like this:
如果您使用的是SQL Server,它将是这样的:
DATEDIFF(d,GETDATE(),FUTUREDATE) BETWEEN 0 AND 90
#1
25
SELECT *
FROM MyTable
WHERE CreatedDate >= getdate()
AND CreatedDate <= dateadd(day, 90, getdate())
http://msdn.microsoft.com/en-us/library/ms186819.aspx
http://msdn.microsoft.com/en-us/library/ms186819.aspx
#2
4
Assuming you have a field for DateTime
, you could have your query look like this:
假设您有一个DateTime字段,您的查询可能如下所示:
SELECT *
FROM TABLE
WHERE DateTime > (GetDate() + 90)
#3
2
For those that want a nice conditional:
对于那些想要一个好条件的人:
DECLARE @MyDate DATETIME = 'some date in future' --example DateAdd(day,5,GetDate())
IF @MyDate < DATEADD(DAY,1,GETDATE())
BEGIN
PRINT 'Date NOT greater than today...'
END
ELSE
BEGIN
PRINT 'Date greater than today...'
END
#4
1
In sql server, you can do
在sql server中,你可以做到
SELECT *
FROM table t
WHERE t.date > DATEADD(dd,90,now())
#5
1
For SQL Server
对于SQL Server
select *
from YourTable
where DateCol between getdate() and dateadd(d, 90, getdate())
#6
1
Select * from table where date > 'Today's date(mm/dd/yyyy)'
You can also add time in the single quotes(00:00:00AM)
您还可以在单引号中添加时间(00:00:00 AM)
For example:
例如:
Select * from Receipts where Sales_date > '08/28/2014 11:59:59PM'
#7
0
If you're using SQL Server it would be something like this:
如果您使用的是SQL Server,它将是这样的:
DATEDIFF(d,GETDATE(),FUTUREDATE) BETWEEN 0 AND 90