Problems with GetUTCDate

  • I need to find the difference between local time and GMT that accounts for both time zone and DST.

    I thought that a smart way would be to call the GetDate() and GetUTCDate() functions, but I get

    the following error:

    Msg 443, Level 16, State 1, Procedure GetUTCtoLocalHourDiff, Line 12

    Invalid use of 'getutcdate' within a function.

    Does this mean I can't use the function?

    Is there a workaround?

    Thanks in advance

  • Yes, there is a work around...

    Create a view that looks like this...

    CREATE VIEW dbo.vGetUTC AS

    SELECT GetUTCDate() AS UTCDate

    Then "call" the view from the function instead of calling GetUTCDate().

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks Jeff!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply