当我选择日期在SQL返回为2011-02-25 21:17:33.933。但我只需要日期部分,即2011-02-25。我该怎么做呢?


当前回答

2008年旧版本:

Select dateadd (day, datediff (day, 0, getdate ()), 0)

其他回答

在PLSQL中可以使用

to_char(SYSDATE,'dd/mm/yyyy')

有点晚了,但是可以使用ODBC的“curdate”函数(尖括号中的“fn”是ODBC函数转义序列)。

SELECT {fn curdate()} 

输出:2013-02-01

你可以这样用

SELECT Convert(varchar(10), GETDATE(),120) 

虽然已经太晚了,但我还是坚持了下来

declare @vCurrentDate date=getutcdate()

select @vCurrentDate

当数据类型为date时,小时将被截断

使用很简单:

convert(date, Btch_Time)

在下面的例子:

表:

Efft_d       Loan_I  Loan_Purp_Type_C   Orig_LTV    Curr_LTV    Schd_LTV    Un_drwn_Bal_a      Btch_Time            Strm_I  Btch_Ins_I
2014-05-31  200312500   HL03             NULL         1.0000    1.0000         1.0000      2014-06-17 11:10:57.330  1005    24851e0a-53983699-14b4-69109

Select * from helios.dbo.CBA_SRD_Loan where Loan_I in ('200312500') and convert(date, Btch_Time) = '2014-06-17'