sql server 2000中如何提取smalldatetime类型数据日期部分,

如2011-6-5 8:00:00,获取2011-6-5,而不是2011-06-05呢
2024-12-14 05:08:36
推荐回答(2个)
回答1:

select CAST(DATEPART(YEAR,GETDATE()) AS VARCHAR(4))
+'-'+CAST(DATEPART(MONTH,GETDATE()) AS VARCHAR(2))
+'-'+CAST(DATEPART(DAY,GETDATE()) AS VARCHAR(2))

回答2:

SELECT REPLACE(CONVERT( char(10),CAST('2011-06-05 8:00:00' AS DATETIME),120),N'-0','-')