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.


3 Answers 3


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

  • Awesome, but now the following displays: 14:01 en-U0 I removed the CultureCode and was left with just the time, but no AM or PM. How would I change this to 12hr from 24hr?
    – Dave
    Jun 29, 2016 at 20:44
  • I've updated my answer above. I think the mask should be hh:mm tt, not HH:MM. Jun 29, 2016 at 20:46
  • Seriously, you're a major help. Last bit, your update worked, but now for some reason the time is being set as 201pm vs. 200pm. Below is the output: 02:01 PM Also, is there a way to have the 0 be conditional so it's not displaying a time like the above?
    – Dave
    Jun 29, 2016 at 20:59

Adam had most of it right but you're getting the same error as I am - you're getting 14:01 because it looks like AMPscript is not differentiating between cases in formatdate(), so your mm is getting displayed as a 2 digit MM month (january in this case as it's the default start month if unspecified). I couldn't get AMPscript to recognize cased date/time format strings so my workaround which is not ideal was to do the following:

%%=DatePart(v(@begin_time), 'hour')=%%:%%=DatePart(v(@begin_time), 'minute')=%% %%=FormatDate(v(@begin_time), 'tt')=%%

That ends up getting me 2:00 PM

EDIT doing DatePart to return Minutes only results in a single 0 which is not helpful when displaying the time. Same works for 'mi' as well.


Your were using an ampscript string call (%%) inside an ampscript block. This is not necessary.

Below the correct code to use :

%%=FormatDate(startTime,"", "hh:mm tt")=%%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .