0

I am having an issue with formatting a date field into a 24 hour time. Below is the FormatDate function I have in my AMPscript. My expected result would be to look like this: 19/05/2020 19:00 - 20:00

My string in the email looks like so:

%%=v(@EventStartDate)=%% - %%=v(@EventEndDate)=%%

My EventStartDate value from my data extension is 5/19/2020 7:00:00 PM My EventEndDate value from the same data extension is 5/19/2020 8:00:00 PM

SET @EventStartDate = FormatDate(@EventStartDate,"dd/MM/YYYY","HH:mm tt","pt-BR")
SET @EventEndDate = FormatDate(@EventEndDate,"HH:mm")

However, when tested in the preview of my records I am getting this result: 19/05/2020 19:00 - 20:05

For some reason it seems to be adding in 5 minutes. Is there something I am missing or have formatted incorrectly?

This is the entire AMPscript in the email:

%%[
Var @EventName, @EventStartDate, @EventID, @FirstName, @SubscriberKey, @EventEndDate 
SET @SubscriberKey = AttributeValue("_subscriberkey") 
SET @EventID = Lookup("ContactToOnlineEvent","Event ID","uuid",@SubscriberKey) 
SET @EventName = Lookup("OnlineEvent","Event Name","Event ID",@EventID) 
SET @EventStartDate = Lookup("OnlineEvent","Event start date","Event ID",@EventID)
SET @EventEndDate = Lookup("OnlineEvent","Event end date","Event ID",@EventID)
SET @FirstName = Lookup("ContactToOnlineEvent","First Name","uuid",@SubscriberKey)
SET @EventStartDate = FormatDate(@EventStartDate,"dd/MM/YYYY","HH:mm tt","pt-BR")
SET @EventEndDate = FormatDate(@EventEndDate,"HH:mm")

]%%
2
  • I think it might be because FormatDate separates the Date and Time parts. Try doing: FormatDate(@EventEndDate,'','HH:mm') and see if that works. Or could change to Format(@EventEndDate,'HH:mm'). (developer.salesforce.com/docs/…) – Gortonington Jun 5 '20 at 15:56
  • @EventEndDate,'','HH:mm' worked! Thank you for the quick response. It is now showing the time in the correct format. – RunRabbit Jun 5 '20 at 16:12
0

Moving from Comment to Answer for easier reference:

I think it might be because FormatDate separates the Date and Time parts in the function:

enter image description here

If you set the function like this: FormatDate(@EventEndDate,'','HH:mm') it should remove the time changes. I am not sure why this happens, but it seems putting any time formats inside the 'date' part changes the time value by a few minutes.

Another way to get around this issue is you could change to Format() instead. Like: Format(@EventEndDate,'HH:mm')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.