-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[XConvertDateE]
(
	-- Add the parameters for the function here
	@date AS VARCHAR(50)
)
RETURNS VARCHAR(50)
	AS 
	BEGIN 
	DECLARE @OutDate datetime2
	SET @OutDate = CASE WHEN CHARINDEX('PM',@date)>0 and CHARINDEX('PM 12',@date)<=0 THEN 
	DATEADD(HH,12,CONVERT (DATETIME, REPLACE(@date,'PM',''))) 
	WHEN CHARINDEX('AM 12',@date)>0 THEN 
	DATEADD(HH,-12,CONVERT (DATETIME, REPLACE(@date,'AM',''))) 
	ELSE CONVERT (DATETIME,REPLACE(REPLACE(@date,'AM',''),'PM','') )
	END 
	RETURN @OutDate 
	END
GO