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?

  • Is the data a text / aka string or is it inside a dataextension and the type date? – Johannes Schapdick Sep 18 at 7:15
5

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

2

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

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.