Runtime verified Test scripts included

Calculates the time difference between two dates in a specified unit.

Syntax

{{dateDiff date1 date2 interval}}

Returns integer.

Parameters

Name Type Required Description
date1 string Yes The first date.
date2 string Yes The second date.
interval string Yes Unit of time: Y, M, D, H, MI, or S.

Example

Tested in a Marketing Cloud Next email on 2026-11-22:

  • {{dateDiff "2025-12-26" "2026-01-05" "D"}} renders 10, as documented.
  • {{dateDiff "2025-01-31" "2025-02-02" "M"}} renders 0, as documented.
  • {{dateDiff "2025-01-31" "2025-02-02" "M" version="ampscript"}} renders 1, as documented.
Show Next test script
<!-- Marketing Cloud Next test script for the dateDiff helper. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[10] got=[{{dateDiff "2025-12-26" "2026-01-05" "D"}}]</p>
<p>c2 expect=[0] got=[{{dateDiff "2025-01-31" "2025-02-02" "M"}}]</p>
<p>c3 expect=[1] got=[{{dateDiff "2025-01-31" "2025-02-02" "M" version="ampscript"}}]</p>

Marketing Cloud Next

Works as documented

Every tested call rendered the documented result. Tested 2026-11-22 by rendering in a Marketing Cloud Next email.

See also