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!
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityAfter 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")
]%%