If function not exist then create function in SQL server
Unfortunately you can't use create function like that. It must be the first statement in a batch.

You can try dynamic SQL instead like:

If not Exists (Select * from sys.objects where name ='FNLX_getDate'  and type =N'FN')
    BEGIN
        DECLARE @sql NVARCHAR(MAX);
        SET @sql = N'CREATE FUNCTION ...';
        EXEC sp_executesql @sql;
    END


Or the classic way (like you can see if you generate scripts with SSMS) : drop and create:

If Exists (Select * from sys.objects where name ='FNLX_getDate'  and type =N'FN')
    drop function [dbo].[FNLX_getDate]
GO
Create function [dbo].[FNLX_getDate]() returns Datetime
as
Begin
.................
End


Notice the GO SSMS batch separator.