AMPscript: Use SystemDateToLocalDate() to Convert a Data Extension Value to Local Time

Scenario

We have a Journey Builder Update Contact Activity writing to a DE field called JourneyEntryDate with the current system timestamp as each contact passes through this canvas activity. In a subsequent email the journey, we wish to add +14 days to this DE datetimestamp and then convert it to the local time.

PROBLEM:

It can be tricky converting a datetime field from a Data Extension to the local date using theSystemDateToLocalDate() function. Error returned “string was not recognized as a valid DateTime.

AMPscript error message

It won’t work because the DE data field we are trying to convert is not a “system” data (noting that SystemDateToLocalDate(Now(1)) will work because it is a system datetime object).

SOLUTION:

The workaround is to format the Data Extension datetime field to ISO value first. This will attach additional datetime details as well as format the DE date correctly making it straightforward for the computer to understand what format the date is in to begin with.

Without this additional information, the computer is unable to know how to format the DE date to the local date since it cannot interpret correctly which is Day and which is Month to begin with.

DEMO:

Related Stack Exchange Question

https://salesforce.stackexchange.com/questions/276510/how-to-use-ampscript-to-correctly-display-date-to-match-correct-country-date-tim

I am a certified Salesforce Marketing Cloud Consultant at Bower House Digital in Melbourne, Australia.