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?
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?
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
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