0

I would like to use AMPscript to convert an epoch date into the following format: MMMM dd, yyyy h:mm tt (eg. April 30, 2018 1:05 PM)

Is this possible with AMPscript?

Thanks!

1

After some research, it doesn't look like AMPScript is able to easily convert Epoch Dates. In this case, I would utilize SSJS to handle it.

Sample using the value from your comment:

<script runat="server">
  Platform.Load('Core','1');

  var utcSeconds = 1525057527200;

  var d = new Date(utcSeconds); // The 0 there is the key, which sets the date to the epoch

  Write(d);
</script>

This will output 4/29/2018 9:05:27 PM

If you need to move it into AMPScript, you can use the following SSJS function: SetValue(1, 2)

which would make the following:

<script runat="server">
  Platform.Load('Core','1');

  var utcSeconds = 1525057527200;

  var d = new Date(utcSeconds); // The 0 there is the key, which sets the date to the epoch

  Platform.Variable.SetValue("@date",d); 
  //Sets the AMPScript variable @date to the value of SSJS var 'd'
</script>

%%[

   SET @formattedDate = FORMATDATE(@date, "MM/DD/YYYY")

]%%
  • Hello, thanks for your reply! Unfortunately I'm not getting the desired result. – Lauren May 7 '18 at 3:21
  • I tried %%=FormatDate(1525057527200, "MMMM dd, yyyy", "h:mm tt", "en-US")=%% and am getting nothing returned. Have you successfully used this script for Unix Epoch date format? – Lauren May 7 '18 at 3:23
  • @Lauren Edited my answer as AMPScript format functions do not work on Epoch dates. – Gortonington May 7 '18 at 14:55

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.