sqlserver数据库日期转换函数

sqlserver数据库日期转换函数

ALTER FUNCTION PR_Sum2 
   ( 
	 @a VARCHAR(80)
	 )
		returns VARCHAR(80)

AS

BEGIN
	declare  @a1 VARCHAR(80) 
	declare  @a2 VARCHAR(80) 
	declare  @a3 VARCHAR(80) 
	declare  @a4 VARCHAR(80) 
	declare  @a5 VARCHAR(80) 
	declare  @a6 VARCHAR(80)
	declare  @a7 VARCHAR(80)
WHILE (@a IS NOT NULL AND @a != '')
BEGIN
	SELECT @a1= (select SUBSTRING (@a,1,4))
	SELECT @a2= (select SUBSTRING (@a,5,2))
	SELECT @a3= (select SUBSTRING (@a,7,2))
	SELECT @a4= (select SUBSTRING (@a,9,2))
	SELECT @a5= (select SUBSTRING (@a,11,2))
	SELECT @a6= (select SUBSTRING (@a,13,2))
	return (select (@a1 +'/'+@a2+'/'+@a3+' '+@a4+':'+@a5+':'+@a6+'.000'))
END
return NULL
END

注意:
将日期类型为20191102200046转换为2019-11-02 20:00:46.000

日期函数:

SELECT ( CONVERT ( VARCHAR, GETDATE( ), 112 ) + '000000' ) 
执行结果:20200812000000

你可能感兴趣的:(sqlserver数据库日期转换函数)