WE HAVE WEBINAR DATE STORED IN UTC FORMAT AND WHEN WE COMPARE THE DATE WITH
SYSTEM DATE , IT SOMETIMES WORK WEIRD. HERE IS THE CODE.
%%[
IF SystemDateToLocalDate('2022-10-31T10:00:00Z') > SystemDateToLocalDate(Now()) THEN
SET @MESSAGE='WEBINAR IS ACTIVE'
ELSE
SET @MESSAGE='WEBINAR HAS EXPIRED'
ENDIF
]%%
SOMETIMES IT WORKS AS INTENDED ,
BUT , SOMETIMES ITS OPPOSITE.
ANALYSIS :
FORMAT () :
THIS AMPSCRIPT FUCNTION FORMATS BASED ON CURRENCY , DEFINES 2nd PARMETER AS C#
COMPATIBLE STRING, SO TO CONVERT DATE, IT'S RECOMMENDED TO AVOID THIS FUCNTION
FORMATDATE() :
THIS USES RFC-1123 COMPATIBLE VALUE , RECOMMENDED TO USE THIS FUCNTION
NOW() :
THIS RETURNS SERVER DATE AND TIME. IT CLEARLY STATES THAT IT DOES NOT REFELCT
WHEN THE ACTUAL SEND OCCURRED. ALSO, NOW() USE CST TIME WITHOUT DAYLIGHT SAVINGS.
IF YOU WANT TO USE TO CAPTURE THE ACTUAL SEND TIME, USE THE FUNCTION
GETSENDTIME()
LOCALDATETOSYSTEMDATE()
USE THIS FUCNTION TO CONVERT THE DATE BEFORE STORING THE CAPTURED DATE
FROM END USERS, SPECIALLY WHEN YOU ARE TARGETING THE END USER ACROSS REGIONS, OR USE FORMATE DATE TO
CONVERT THE DATE INTO CST TIME ZONE.
SYSTEMDATETO LOCALDATE()
USE THIS FUCNTION, SPECIALLY WHEN YOU ARE ALLOWING USER TO DOWNLAOD CALENDAR IN
AN ICS FORMAT. IT WILL SET THE MEETING INVITE TIME TO THE LOCAL TIME ZONE OF THE USER.
CANDENCE :
HERE IS THE FULL COMPARISON OF THE DATE FUNCTIONS:
%%[
SET @webinarStartTimeInUTC = '2022-10-31T10:00:00Z'
SET @webinarStartTimeInCST = FormatDate(@webinarStartTimeInUTC,"MM/dd/yyyy","l", "en-US")
SET @systemTime=Now()
SET @systemTimeCST= FormatDate(@systemTime, "MM/dd/yyyy","l", "en-US")
SET @webinarStartTimeInLocalDate= SystemDateToLocalDate(@webinarStartTimeInUTC)
SET @systemTimeLocalDate= SystemDateToLocalDate(@systemTime)
IF DateDiff(@webinarStartTimeInCST,@systemTimeCST, 'D') <= 0 THEN
SET @MESSAGE_CST= 'WEBINAR IS ACTIVE USING CST FORMAT'
ELSE
SET @MESSAGE_CST= 'WEBINAR HAS EXPIRED USING CST FORMAT'
ENDIF
IF DateDiff(@webinarStartTimeInLocalDate,@systemTimeLocalDate, 'D') <= 0 THEN
SET @MESSAGE_LOCAL=' WEBINAR IS ACTIVE USING LOCAL DATE'
ELSE
SET @MESSAGE_LOCAL='WEBINAR HAS EXPIRED USING LOCAL DATE'
ENDIF
IF @webinarStartTimeInLocalDate > @systemTimeLocalDate THEN
SET @MESSAGE_OPERATOR_LOCAL= 'WEBINAR IS ACTIVE USING LOCAL DATE'
ELSE
SET @MESSAGE_OPERATOR_LOCAL= 'WEBINAR HAS EXPIRED USING LOCAL DATE'
ENDIF
IF @webinarStartTimeInCST > @systemTimeCST THEN
SET @MESSAGE_OPERATOR_CST= 'WEBINAR IS ACTIVE USING LOCAL DATE'
ELSE
SET @MESSAGE_OPERATOR_CST='WEBINAR HAS EXPIRED USING LOCAL DATE'
ENDIF
IF SystemDateToLocalDate(@webinarStartTimeInUTC) > SystemDateToLocalDate(Now()) THEN
SET @MESSAGE_OPERATOR_CST_OLD= 'WEBINAR IS ACTIVE USING LOCAL DATE'
ELSE
SET @MESSAGE_OPERATOR_CST_OLD= 'WEBINAR HAS EXPIRED USING LOCAL DATE'
ENDIF
IF SystemDateToLocalDate('2022-10-31T10:00:00Z') > SystemDateToLocalDate(Now()) THEN
SET @MESSAGE_LOCAL_COMPARE_OPRATOR_OLD= 'WEBINAR IS ACTIVE USING LOCAL DATE OPERATOR OLD'
ELSE
SET @MESSAGE_LOCAL_COMPARE_OPRATOR_OLD= 'WEBINAR HAS EXPIRED USING LOCAL DATE OPERATOR OLD'
ENDIF
]%%
ALL THE
IF-ELSE WORKS PERFECTLY EXCEPT THE LAST 2, INTERMITTEN ISSUES ARE OBSERVED BECAUSE OF THE INPUT
PARAMTERS THAT HAS BEEN PASSED ARE NOT IN THE SAME FORMAT.
ALWAYS CONVERT BOTH THE DATES INTO CST (SYSTEM
TIME) FORMAT WITH A CULTURE CODE BEFORE MAKING ANY COMPARISON, INCLUDING NOW() FUNCTION, BEACUSE ,
THE OUTPUT FOR "M" VARIES DEPENDING ON WHETHER "M" IS USED AS A SINGLE FUNCTION OR A GROUP OF FUNCTIONS.
HERE IS THE EXAMPLE:
%%[
SET @webinarStartTimeInUTC = '2022-08-31T15:00:00Z'
SET @webinarStartTimeInCST =
FormatDate(@webinarStartTimeInUTC, "MM/dd/yyyy", "l", "en-US")
SET @systemTime=Now()
SET @systemTimeCST= FormatDate(@systemTime, "MM/dd/yyyy", "l", "en-US")
IF DateDiff(@webinarStartTimeInCST, @systemTimeCST, 'D') <= 0 THEN
SET @MESSAGE='WEBINAR IS ACTIVE'
ELSE
SET @MESSAGE='WEBINAR HAS EXPIRED'
ENDIF
]%%
Comments
Post a Comment