获取 SQLServer 中的当前日期?

如何在 MS-SQLServer2008R2中获得当前日期?

我数据库中的列的格式是 DATETIME,日期以下列格式存储:

+++++++++++++ Vrdate ++++++++++
|                             |
|   2012-11-18 00:00:00.000   |
|   2012-11-19 00:00:00.000   |
|   2013-11-18 00:00:00.000   |
|   2012-12-01 00:00:00.000   |
|   2010-10-09 00:00:00.000   |
|   2012-11-11 00:00:00.000   |
|                             |
+++++++++++++++++++++++++++++++

我搜索了一下,但是找不到以这种格式获取日期的方法(也就是说,在 00:00:00.00中与日期相关的时间)。我找到了 GETDATE()函数,但它提供了当前时间以及日期,我想要的是得到以下格式的日期: CurrentDate 00:00:00.00

我怎么才能拿到这个?

331281 次浏览
SELECT CAST(GETDATE() AS DATE)

Returns the current date with the time part removed.

DATETIMEs are not "stored in the following format". They are stored in a binary format.

SELECT CAST(GETDATE() AS BINARY(8))

The display format in the question is independent of storage.

Formatting into a particular display format should be done by your application.

As you are using SQL Server 2008, go with Martin's answer.

If you find yourself needing to do it in SQL Server 2005 where you don't have access to the Date column type, I'd use:

SELECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)

SQLFiddle