[SalesForce] Change Date & Time Format in AMPScript Populated content

I'm working on an e-mail in SalesForce Marketing Cloud that uses AMPScript to populate and event start time. The data extension field that populates the AMP Script is set as a text field, unfortunately that means that times are being set to include seconds instead of just hours and minutes.

Here's what I started with:%%StartTime%% which populates as 2:00:00 PM

I tried the replace function%%=Replace(@StartTime,':00',' ')=%%however this left the field blank.

So I tried %%=FormatDate(%%StartTime%%, "HH:MM", "en-US")=%% and %%=FormatDate(2:00:00 PM, "HH:MM", "en-US")=%% was returned.

Ideas?

Best Answer

Should be this without the double %%:

%%=FormatDate(StartTime, "hh:mm tt, "en-US")=%%

or better:

%%[

var @startTime
set @startTime = AttributeValue("StartTime")
set @startTime = FormatDate(@startTime, "hh:mm tt", "en-US")

]%%

It's currently %%=iif(empty(@startTime), "HAMMER TIME!", @startTime)=%%

Reference: MSDN DateTimeFormatInfo Class

Related Topic