0

I have a requirement to output only time from date/time field in a SalesForce campaign for an email I am working on.

I had to split up the date/time in order to format as desired.

SET @Delivery = [Customer_Delivery__c]
SET @DeliveryDay = FormatDate(@Delivery, "ddddd, MMMM d, yyyy", "", "en-US")
SET @DeliveryTime = FormatDate(@Delivery, "", "H:mm tt", "en-US")

Here is my output code:

%%=v(@DeliveryDay)=%% %%=DateAdd(@DeliveryTime, "-4","H")=%%  

I should mention that I had an additional requirement to subtract 4 hours from the delivery time.

I did so by using the DateAdd function to subtract 4 hours. - Now the problem is that when I use DateAdd the output after running the code is:

Monday, October 1, 2018 10/1/2018 2:30:00 PM

I want to remove the 10/1/2018 line. - How can I exclude the duplicate output of the date?

Desired output should be:

Monday, October 1, 2018 2:30:00 PM

When I don't use DateAdd it does not give me duplicate date but I have to use DateAdd to display the correct time.

All help here would be greatly appreciated!

0

I'm not familiar with the syntax you are using, but there are issues with splitting before subtracting the hours - if delivery time is before 4AM the delivery date should switch to the day before.

Could you simply not do the following:

SET @Delivery = [Customer_Delivery__c]
SET @DeliveryDayTime = FormatDate(DateAdd(@Delivery, "-4", "H"), "ddddd, MMMM d, yyyy", "h:MM tt", "en-US")

%%=v(@DeliveryDayTime)=%% 

I.e. wrap the DateAdd so it is the first parameter of a call to FormatDate, and have FormatDate handle both the date and time from that value?

  • Thank you for the reply Phil! I have the date and time split into two strings based on one attribute. The default output is: 9/21/2018 12:00 AM What I want instead is: Monday, October 1, 2018 2:30:00 PM %%=v(@DeliveryDay)=%% output is: Monday, October 1, 2018 which is what I want for the date. For the time I'm using: %%=DateAdd(@DeliveryTime, "-4","H")=%% except it is including an extra date. I'll have to try your string when I get home, but the complete output I am looking for is: Monday, October 1, 2018 2:30:00 PM Will mark answered if what you say works. – AMPvoyager Oct 1 '18 at 21:57
  • Hi Phil, following up. - Your updated script worked! The only thing now is that the time is output in military, is there a way to change to standard? - According to documentation I need to add "s" to the function, however there does not seem to be anymore room. developer.salesforce.com/docs/… – AMPvoyager Oct 1 '18 at 23:04
  • I assume by "military" you mean 24hr clock, so for 8PM it's saying 20? If so, try changing from "H:mm tt" to "h:mm tt"? Like I said, I don't know AMP so I'm just guessing. – Phil W Oct 2 '18 at 16:38
  • Correct, I was able to adjust to the correct output but I have one last caveat. - The new string you posted is still including the date along with the hours. This is the new output: Monday, October 1, 2018 10/2/2018 2:30:00 PM - Do you have any idea why this is happening? I feel the empty "" should suffice for leaving the date blank. Is there a way I could reinforce this so the the string will exclude 10/2/2018? – AMPvoyager Oct 2 '18 at 17:38
  • Hey @AMPvoyager, I would have expected "%%=v(@DeliveryDay)=%% %%=FormatDate(DateAdd(@DeliveryTime, "-4","H"), "", "h:mm tt", "en-US")=%%" to not include the date in the output because we are explicitly calling FormatDate to only get the "h:mm tt" (12hr hours, minutes and AM/PM indicator). Is that what you are using now? – Phil W Oct 3 '18 at 10:28

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.