CREATE PROCEDURE dbo.SystemDateTime @ADateStr CHAR(8), @ASystemDateTime DATETIME OUTPUT AS
/*
  Created by Kent Johansen, February 2024
  Get system date and time
*/
DECLARE @TimeZone VARCHAR(100)
DECLARE @CurrentDateStr CHAR(8)

SELECT @TimeZone = KeyValue FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'TimeZone'
IF ISNULL(@TimeZone, '') = ''
  SET @TimeZone = 'Romance Standard Time'

IF ISNULL(@ADateStr, '') <> ''
  SET @CurrentDateStr = @ADateStr
ELSE
  SELECT @CurrentDateStr = SystemDate FROM System WITH (NOLOCK) WHERE Number = 1

SET @ASystemDateTime = CONVERT(DATETIME, @CurrentDateStr + ' ' + CONVERT(VARCHAR(8), CURRENT_TIMESTAMP AT TIME ZONE 'Romance Standard Time' AT TIME ZONE @TimeZone, 108))