sqlserver 自定义日期函数(yyyy-MM-dd)

if object_id('getDateFormat1') is not null  
    drop function getDateFormat1
go
create function getDateFormat1(@dt datetime)  
returns varchar(10)  
as  
begin  
    DECLARE @now VARCHAR(10)  
    set @now = STUFF(STUFF(
      CONVERT(char(8),@dt,112),
      5,0,N'-'),8,0,N'-')+N''
    return @now  
end

测试:

select dbo.getDateFormat1('2010-04-06 16:52:04.093');

结果 :  

2010-04-06

猜你喜欢

转载自xurichusheng.iteye.com/blog/1833147
今日推荐