I see here that S1 = The part of the date to retrieve. Valid values include year (Y), month (M), monthname, day (D), hour (H), and minute (MI). I don't see a script to isolate the part of the datestamp which would indicate AM/PM. Is there one?

  • 1
    In my testing, I actually don't think we allow that...I am looking for a workaround. – Kelly J Andrews Mar 18 '14 at 19:46

I don't believe there is such a function. The reason being that AM/PM data is not stored in the date; the date is stored in 24h format and AM/PM would need to be calculated. A possible workaround: if you need to just display it nicely on a landing page, then you could format it client side using something like date.js. Otherwise you could use SSJS and use a function to do it like the following, only modifying it to run server side:

function formatAMPM(date) { var hours = date.getHours(); var minutes = date.getMinutes(); var ampm = hours >= 12 ? 'pm' : 'am'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' minutes = minutes < 10 ? '0'+minutes : minutes; var strTime = hours + ':' + minutes + ' ' + ampm; return strTime; }

(Taken from https://stackoverflow.com/questions/8888491/how-do-you-display-javascript-datetime-in-12-hour-am-pm-format)

  • I believe that is true of a unix datestamp but it appears that the AMPscript datestamp does have a built-in AMPM indication and is not a 24 hour time. I'm not sure of that but someone who knows may clear that up for us. – Jonny Shaw Mar 18 '14 at 20:34

The suggestion below is certainly valid and may have benefits over my own workaround but I figured out a fairly easy "AMPscript only" solution. I used concat to set the AMPM value in the datestamp and it works but, the challenge is getting it to set a DatePart for the form that sets the events time as there is no method in datepart specific to the AMPM appendage.

So what I did is created a separate field in the data extension which ALSO holds the AM/PM setting of the record. When we update a record, it now uses the @ampm variable from the dropdown menu both to set the value in the concatenated datestamp and ALSO to set the AMPM value in the specific data extension column which only holds that information.

Now when the landing page reads the data extension it sets the dropdown based on the ampm column, and if that is changed and submitted it will update both that field AND the datestamp. An extra field to mimic data which otherwise can't be isolated. Simple and effective.


I haven't validated this, but could you use the FormatDate() function?

FormatDate([attribute/variable], 'tt')

I think this should return AM or PM.

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.