sqlserver 自定义日期函数(yyyy-MM-dd)
程序员文章站
2022-03-11 09:01:48
...
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