Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Last active July 29, 2021 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzkmx/b8cd8b49592faf5653d212677593a6d2 to your computer and use it in GitHub Desktop.
Save tzkmx/b8cd8b49592faf5653d212677593a6d2 to your computer and use it in GitHub Desktop.
Trigger to fix datetime offset in Laravel Nova
CREATE OR
ALTER PROCEDURE assets.sp_webinar_fix_utc_date @webinar_id BIGINT
AS
BEGIN
DECLARE @fixed_start_date DATETIMEOFFSET;
DECLARE @fixed_end_date DATETIMEOFFSET;
SET @fixed_start_date = (SELECT DATEADD(hh, 5, start_date) AT TIME ZONE 'Central Standard Time'
FROM assets.webinars
WHERE id = @webinar_id);
SET @fixed_end_date = (SELECT DATEADD(hh, 5, end_date) AT TIME ZONE 'Central Standard Time'
FROM assets.webinars
WHERE id = @webinar_id);
UPDATE assets.webinars
SET start_date = @fixed_start_date,
end_date = @fixed_end_date
WHERE id = @webinar_id;
END
CREATE TRIGGER assets.sp_temporal_webinar_patch_dates
ON assets.webinars
AFTER INSERT, UPDATE AS
BEGIN
DECLARE @webinar_id BIGINT;
SET @webinar_id = (SELECT id FROM inserted);
EXEC assets.sp_webinar_fix_utc_date @webinar_id;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment