This FAQ is linked to my other FAQ which helps to return the SQL Server TIMEZONE from a User Defined Function.
Due to SQL determinism; If you try to use the GetDate() or GetUTCDate() function within a User Defined Function, you will get an error message: Error 443: Invalid use of 'getdate' within a function.
-or- Error 443: Invalid use of 'getutcdate' within a function.
If you want to return the CURRENT GMT/UTC time on the SQL Server, you need to do:
1. You create VIEW first:
[color blue]CREATE VIEW dbo.SYS_GetUTCDateTime
AS
SELECT GETUTCDATE() AS UTCDateTime[/color]
2. You create a USER DEFINED FUNCTION:
[color blue]CREATE FUNCTION dbo.fniGetUTCDateTime( )
RETURNS DATETIME AS
BEGIN
DECLARE @vdUTC DATETIME
SELECT @vdUTC = UTCDateTime FROM SYS_GetUTCDateTime
RETURN @vdUTC
END[/color]
Replace the GetUTCDate() with GetDate() if you just want to return the current server local (system) time.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.