I'm new to AMPScript. I'm working with a Journey with SF Data Entry Source, specifically trying to send emails after someone registers for an event (which is logged in CRM).

I want to add six hours to the time logged in CRM, coming into SFMC via a data extension column called Event_Attendee_Enrollment__c:Event__r:Start_Time__c.

VAR @StartDate, @NewDate
SET @StartDate = AttributeValue(‘Event_Attendee_Enrollment__c:Event__r:Start_Time__c’)
SET @NewDate = DateAdd(@StartDate, 6, “H”)


%%=Format(@NewDate, “HH:mm”)=%%

But I am getting this error:

The subscriber preview failed to generate. Review the details, correct all issues, and try again. An expected comma is not found in the varible declaration.

Script: VAR @StartDate @NewDate
ListID: 147 Index: 13286

Where am I going wrong?

  • can you doublecheck the VAR @StartDate, @NewDate line? The way I quoted it now it looks correct, but the error message complains about the comma not being there. if the comma is there in your code, but you keep getting the error then try leaving it out. It is not technically necessary to have the VAR declaration, you can start with SET. Dec 11, 2021 at 11:43
  • @JonasLamberty, thanks for the tip. I removed the VAR declaration and it worked as expected. So strange about the comma, as it was indeed there, but possibly a fluke. Appreciate the help!
    – jazzyjems
    Dec 11, 2021 at 22:55
  • Also - as a note, declaring Var in AMPscript is pretty unnecessary. It is defined as a best practice, but from everything I have seen, it only ever really seems to cause problems more than be helpful. The only time I have seen to declare them is if you are looking for an undefined value - but in that case, not declaring it also gives it this value by default. Not saying do not do it - just sharing an opinion that may help remove issues like this in the future. Dec 15, 2021 at 14:46
  • @Gortonington this is very helpful advice, thanks!
    – jazzyjems
    Dec 16, 2021 at 18:16

1 Answer 1


A few things... You've got some curly quotes in there -- that's not going to work.

The var is unnecessary as others have already mentioned.

I'd recommend checking to make sure you're date is not empty before attempting to apply the dateadd() and format() functions. The raiseError function will let you skip a send to specific subscriber if the data requirements are not met.

Lastly, the format pattern is incorrect. I'd recommend %%=format(@NewDate,"hh:mm","Date")=%%. The MM in your example will return the month, not the minutes.


SET @StartDate = AttributeValue("Event_Attendee_Enrollment__c:Event__r:Start_Time__c")

if not empty(@StartDate) then
  set @NewDate = DateAdd(@StartDate, 6, "H")
  raiseError("invalid StartDate",1)


You must log in to answer this question.

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