如何在没有时间部分的情况下获取当前日期 [英] How to the get current date without the time part

查看:131
本文介绍了如何在没有时间部分的情况下获取当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server 2005中,如何在没有时间部分的情况下获取当前日期?我一直在使用GETDATE(),但希望它的时间为00:00:00。

In SQL Server 2005 how do I get the current date without the time part? I have been using GETDATE() but would like it to have a time of 00:00:00.

推荐答案

解决方案1由_Canny_Brisk_ [ ^ ]非常好,如果您使用SQL Server 2008及更高版本,建议您使用。除此之外(以防你使用SQL Server 2005),试试这个:

Solution 1 by _Canny_Brisk_[^] is very good and recommended to you, if you use SQL Server 2008 and up. In addition to it (just in case you use SQL Server 2005), try this:
SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)





资料来源:删除SQL Server中datetime时间部分的最佳方法 [ ^ ]


以上解决方案非常好,你也可以像使用它一样---









仅限日期 -



选择CONVERT(varchar(10),getdate(),120)AS coDate1



输出 - 2015-04-20







仅限时间



选择CONVERT(varchar(10),getdate(),108)AS coTime1



输出 - 14:42:35
Above solution is very good and you can also use this as like an alternate ---




Only for date-

select CONVERT(varchar(10), getdate(), 120)AS coDate1

output-- 2015-04-20



Only for time

select CONVERT(varchar(10), getdate(), 108)AS coTime1

output-- 14:42:35


您标记了问题SQL-Server-2008R2,在这种情况下使用:

You tagged the question SQL-Server-2008R2, in which case use:
Convert(date, getdate())





但是,问题本身你说的是SQL Server 2005,在这种情况下,使用:



BUT, in the question itself you stated SQL Server 2005, in which case, use:

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





干杯,

C



Cheers,
C


这篇关于如何在没有时间部分的情况下获取当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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