0

I am trying to pull in DoB from a Data extension via ampscript and change the date format to be 'yyyymmdd' where am i going wrong?

  %%[var @DoB, SET @DoB = [Date_of_Birth__c] ]%%
   set @DoB = FormatDate(Now(),"YYYYMMDD")
   
   ]%%
   
   %%[ENDIF]%%

Then in the copy i put %%=v(@DoB)=%% ...yet it still pulls through this for example: 9/19/2003 12:00:00 AM

1
  • it looks like you are setting the @DoB variable multiple times. Without the rest of your script I can just tell you to check and see if its updated again prior to being written out which is overwriting your formatting OR you should change the formatted date variable name and call that instead.in your output to ensure it is retained Dec 15, 2020 at 18:15

1 Answer 1

1

@Gortonington is correct. Not only are you setting the @DoB variable multiple times, but there a bunch of syntax errors in your AMPscript.

  1. %%[var @DoB, : You have a comma at the end of this var statement but with no other variables
  2. SET @DoB = [Date_of_Birth__c] ]%% : The AMPscript block is closed here at the end when below that you have more AMPscript coding
  3. set @DoB : The @DoB variable is being overwritten.
  4. FormatDate(Now(),"YYYYMMDD") : The wrong date is being formatted. You're using Now() which is obviously now.
  5. %%[ENDIF]%% : There is no IF statement in your example.

Here is one way to correctly write the AMPscript:

%%[ var @date, @DoB

set @date = [Date_of_Birth__c]
set @DoB = FormatDate(@date,"YYYYMMDD")
   
]%%
%%=v(@DoB)=%%

You must log in to answer this question.

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