Runtime verified Differs from official docs Test scripts included

Syntax

Length(sourceString)  →  number
1 argument — exactly

Parameters

Name Type Required Description
sourceString string | date Yes Value to measure

A number or boolean argument saves but makes the email fail to render — see below.

Example

%%=Length("Hello")=%%

Renders 5.

An empty string measures zero:

%%=Length("")=%%

Renders 0.

Return value

number — the count of UTF-16 code units in the value.

Every successful call rendered a plain non-negative whole number. There is no fixed set of special values.

Behaviour

Plain ASCII counts one per character. Length("Hello World") gives 11 and Length("abcd") gives 4.

The unit is the UTF-16 code unit. Length("café") gives 4 and Length("Straße") gives 6, because each of those letters is one code unit. A single emoji such as 😀 gives 2: it is one visible character but two code units. A character limit enforced with Length therefore allows one character fewer for each emoji.

Dates are measured as text. Length(Now()) gave 19, the length of a value like 2026-11-23T00:21:32.

Numbers and booleans break the preview. An email with Length(12345) or Length(true) saves, but rendering it fails with HTTP 500. Measure numbers as text by passing them as a string.

No argument or two arguments cannot be saved. Length() and Length("a", "b") are rejected at save with HTTP 400 “The AMPscript syntax isn’t valid”.

Show Next test script
<!-- Marketing Cloud Next test script for Length. 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=[5] got=[%%=Length("abcde")=%%]</p>
<p>c2 expect=[0] got=[%%=Length("")=%%]</p>
<p>c3 expect=[5] got=[%%=Length("Hello")=%%]</p>
<p>c4 expect=[11] got=[%%=Length("Hello World")=%%]</p>
<p>c5 expect=[4] got=[%%=Length("abcd")=%%]</p>
<p>c6 expect=[4] got=[%%=Length("café")=%%]</p>
<p>c7 expect=[6] got=[%%=Length("Straße")=%%]</p>
<p>c8 expect=[2] got=[%%=Length("😀")=%%]</p>
<p>c9 expect=[19] got=[%%=Length(Now())=%%]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(12345)=%%

<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(true)=%%

<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=Length()=%%

<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=Length("a", "b")=%%

Differs from official docs

  • The unit is the UTF-16 code unit. The reference does not name a unit; in Next Length("😀") is 2. Card
  • Numbers and booleans break the render. The reference does not rule them out, but Length(12345) and Length(true) made the Next preview fail with HTTP 500. Card

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 67.0

See also