• :laugh: I wish I was still 46!

    When I saw your question last night I remembered a similar scenario concerning UniData date conversions on which I made a post.

    UniData date function.

    UniData dates use a boundary of 31 Dec 1967 so I guess that year stuck in my head. UniData dates are based on the number of seconds before or after 31 Dec 1967 so that earlier post would have been pretty close to a solution as it was by just adding two sets of numbers.

    What got me going this time though really didn't have much to do with the number of seconds since 1900. Rather, I wanted to see if I could incorporate SET commands within a function. The original UniData function is an inline TVF. So I took a dive to see if there was some method for making SET DATEFORMAT and SET LANGUAGE work in an inline TVF. (Alas, I think the answer is no.) So the script I had to settle for required a stored procedure.

    But I learned a new trick in the process using QUOTENAME as a method for executing a SET command in a SELECT statement like this:

    SELECT QUOTENAME('SET DATEFORMAT '+@DateFormat,'''')

    So perhaps it really is possible to do a SET within a function.