Is there any way to get the current time for particular given time zone?
For EX: GetDateTime("Morocco Standard Time")
It should give the local time of time zone "Morocco Standard Time"
Thanks in Advance, Merlin
Is there any way to get the current time for particular given time zone?
For EX: GetDateTime("Morocco Standard Time")
It should give the local time of time zone "Morocco Standard Time"
Thanks in Advance, Merlin
I know that the question is quite old, but maybe the answer will help someone.
If you are using SQL Server 2016 you can use new feature
AT TIME ZONE
. Let's get to the result that you need step by step.First, use function
SYSDATETIMEOFFSET()
to retrieve current date and time in UTC time zone. The return type of this function isDATETIMEOFFSET
, which stores not only date, but also related time zone information:Then this with
AT TIME ZONE
statement. This returnsDATETIMEOFFSET
in the time zone that you need:Additionally if you want to lose time zone information and use
DATETIME
, you can cast the above result toDATETIME
: