Home > Back-end >  How to insert a time-zoned converted Timestamp into a table?
How to insert a time-zoned converted Timestamp into a table?

Time:12-21

How can I set my timestamp to a specific time zone, particularly US/Pacific?

Consider this MWE:

CREATE TABLE #timingTable (theTime datetime2(0))

INSERT INTO #timingTable SELECT (SELECT CURRENT_TIMESTAMP);
select * from #timingTable;

CodePudding user response:

You can use SYSDATETIMEOFFSET to get the current time with the offset, and then use AT TIME ZONE to convert it to the timezone you want the datetime stored in.

CREATE TABLE #timingTable (theTime datetime2(0))

INSERT INTO #timingTable SELECT SYSDATETIMEOFFSET() AT TIME ZONE 'Pacific Standard Time';

select * from #timingTable;

CodePudding user response:

(SELECT CURRENT_TIMESTAMP AT TIME ZONE 'Pacific Standard Time'); 

I would read these docs and see if it helps clarify.

  • Related