0

I have a data 9/14/2019 4:37:57 PM

I want to format this to: 20190914T163757

How do I format it so that if it includesPM to 24hour using ampscript?

1
  • Is the data a text / aka string or is it inside a dataextension and the type date? Commented Sep 18, 2019 at 7:15

2 Answers 2

3

You can get exactly your desired output using the following:

%%[
SET @time = "9/14/2019 4:37:57 PM"
SET @formatted = Replace(FormatDate(@time, "YYYYMMDDT","HHMMSS"),' ','')
]%%
%%=v(@formatted)=%%

Output: 20190914T163757

6

The closest you can get to this is by using the FormatDate AMPscript function with ISO pattern:

set @dateString = "9/14/2019 4:37:57 PM"
set @dateISO  = FormatDate(@dateString,"iso")

%%=v(@dateISO)=%% outputs: 2019-09-14T16:37:57.0000000

You can then format this further using Replace and Substring functions:

set @dateString = "9/14/2019 4:37:57 PM"
set @dateISO  = FormatDate(@dateString,"iso")
set @dateReplace = Replace(Replace(@dateISO, "-", ""), ":", "")
set @dateSubstring = Substring(@dateReplace,1, Subtract(IndexOf(@dateReplace,"."),1))

%%=v(@dateSubstring)=%% outputs: 20190914T163757

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .