在oracle中,
select to_timestamp('2010-04-16 16:52:04.093','YYYY-MM-DD HH24:MI:SS.FF3') from dual;
结果是:16-APR-10 04.52.04.093000000 PM
如何在SQL SERVER 中实现这样的功能
--自定义函数实现:
/*------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-04-17 10:07:56
-- Version: Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34
Copyright (c) 1988-2008 Microsoft Corporation
Developer Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
------------------------------------------------------------------*/
if object_id('dbo.getdt') is not null
drop function dbo.getdt
go
create function dbo.getdt(@dt datetime)
returns nvarchar(30)
as
begin
return(datename(dd,@dt)+'-'+
case month(@dt)
when 1 then 'Jan'
when 2 then 'Feb'
when 3 then 'Mar'
when 4 then 'Apr'
when 5 then 'May'
when 6 then 'Jun'
when 7 then 'Jul'
when 8 then 'Aug'
when 9 then 'Sep'
when 10 then 'Oct'
when 11 then 'Nov'
else 'Dec'
end+'-'+right(datename(yy,@dt),2)+' '+
stuff(right('0'+ltrim(stuff(
replace(convert(varchar,@dt,9),':','.')
,1,10,'')),14),13,0,' ')
)
end
go
--调用:
select dbo.getdt('2010-04-16 16:52:04.093')
--result:
--16-Apr-10 04.52.04.093 PM