我有以下脚本返回格式化为US的日期,id喜欢将其转换为GB日期格式,它应该只返回日期部分。
SET DATEFIRST 1
select case @dateType
WHEN 'Daily' then i.overridedate
WHEN 'Weekly' then dateadd(day,-1*datepart(weekday,i.overridedate)+1,i.overridedate)
WHEN 'Monthly' THEN DATEADD(day, -1*DATEpart(day,i.overridedate)+1, i.overridedate)
WHEN 'Quarterly' THEN dateadd(mm,-3,DATEADD(qq, DATEDIFF(qq,0,i.overridedate )+1, 0)) END as 'date'
答案 0 :(得分:1)
我相信你可以使用转换功能:
SELECT convert(varchar, getdate(), 105)
对于GB,正确的样式将是103,基于此表:http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/
105是造型。我在这个博客上找到了这个技巧:http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/