简体   繁体   English

如何在SQL中显示将来的日期和今天的日期

[英]How to display future date and today date in SQL

I have this and wish to display future date and today date how can it be done? 我有这个,希望显示将来的日期和今天的日期怎么办?

Date
-----------
10/08/2014
09/08/2014
11/08/2014

and I only wish to display 我只想展示

10/08/2014
11/08/2014

Most versions of SQL have some way of getting the current date. 大多数版本的SQL都有某种获取当前日期的方法。 For instance: 例如:

where date >= cast(CURRENT_TIMESTAMP as date)
where date >= cast(getdate() as date)
where date >= date(now())
where date >= trunc(date)

The specific syntax you need depends on the database you are using. 您需要的特定语法取决于您所使用的数据库。

EDIT: 编辑:

The first or second versions should work with SQL Server Express. 第一个或第二个版本应与SQL Server Express一起使用。

SQL will consider your date "11/08/2014" in mm/dd/yyyy format by default. 默认情况下,SQL会以mm / dd / yyyy格式考虑您的日期“ 11/08/2014”。 You would need to rearrange the month before the date like "08/11/2014" before making the comparison. 在进行比较之前,您需要重新排列日期前的月份,例如“ 08/11/2014”。 Below code will get you the required results: 下面的代码将为您提供所需的结果:

SELECT CONVERT(VARCHAR(20),CAST(Time AS DATE),120)
FROM Table
WHERE CONVERT(VARCHAR(20),CAST(Time AS DATE),120)>=CONVERT(VARCHAR(20),GETDATE(),120)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM