AMPscript DateTime Functions

AMPscript DateTime functions allow us to manipulate display format, perform math functions, and control email content using static, dynamic, and real-time values with:

  • Now(1) Campaign Sends
  • Now(1) Triggered Sends
  • DateAdd(1, 2, 3)
  • DateDiff(1, 2, 3)
  • DateParse(1, 2)
  • DatePart(1, 2)

Now(1) Function – Campaign Sends

The Now() function is used to capture the system DateTime at the time of send. The system uses Central Standard Time and does not adjust for Daylight Savings Time. Now() returns a dynamic date that will update when using in an email VAWP (View As Web Page) link and or landing pages. You’ll want to use Now(1) to preserve the date at the time of send.

Example
%%=Now(1)=%%


Now(1) Function – Triggered Sends

Now(1) doesn’t work as expected for triggered sends. When used in a triggered send, it returns the last time the triggered-send-definition was published. If you need to maintain the accurate send time and date in a trigger (i.e. for VAWP links,) use this workaround: Add a date field to the triggered DE (name it something like “DateAdded”) and auto-populate it with the current date. This sets that field to the date/time the record was added to the DE (the date/time the triggered email was sent).


Date Add Function

The DateAdd() function is used to increase or decrease the date time value. It can be used with a date object or with the Now() function. You need to date objects in order for this to work.

Example
%%=DateAdd(1, 2, 3)=%%


Date Diff Function

The DateDiff() function returns the difference between two date values. Always use DateDiff() when comparing DateTime values otherwise they will be compared as string values.

Example
%%=DateDiff(1, 2, 3)=%%


Date Parse Function

The DateParse() function is used to convert a string into a DateTime object. Date might be provided as a string in the incorrect format so DateParse() converts it into a DateTime object in the proper format.

Example
%%=DateParse(1, 2)=%%


Date Part Function

The DatePart() function isolates specific elements of a date object. This function is useful when having to break apart a date to format it around specific business requirements. It’s especially helpful converting dates to support other languages.

Example
%%=DatePart(1, 2)=%%


Gallery