I have an SP with a bunch of queries that use datetime like Getdate().
Is there a way that I can set a global flag at the beginning of the SP to set a timezone offset for the datetimes?
I need something like the set dateformat dmy, but to offset the timezone.
There is no magical global offset variable that will change the time reported by SQL Server for a a session. If you think about it, you’ll notice that variables declared in a procedure never affect the server. You’d need something in, say, the SET command to do that.
I assume the application provides the offset, based on the TZ database or equivalent, and you just want to apply it as easily as possible. What you could do is wrap
getdate()with a new functionlocaledate()that accepts as input the offset and applies it togetdate()withdateadd().Bear in mind that dates saved in the database have no associated time zone. Localizing them would be a bigger undertaking.