在SQL Server中获取当前日期? [英] Getting the current date in SQL Server?

查看:82
本文介绍了在SQL Server中获取当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取MS-SQL Server 2008 R2中的当前日期?

How can I get the current date in MS-SQL Server 2008 R2?

数据库中列的格式为 DATETIME 和日期以以下格式存储:

The format of the column in my database is DATETIME and dates are stored in the following format:

+++++++++++++ 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

I searched but wasn't able to find the way to get the date in this format (i.e. which has the time associated with it in 00:00:00.00). I found GETDATE() function but that provides the current time along with the date as well, what I want is get the date in the following format: CurrentDate 00:00:00.00

我怎么能得到这个?

推荐答案

SELECT CAST(GETDATE() AS DATE)

返回删除了时间部分的当前日期。

Returns the current date with the time part removed.

DATETIME 不存储以以下格式。它们以二进制格式存储。

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.

这篇关于在SQL Server中获取当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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