Runtime verified Differs from official docs Test scripts included

Syntax

FormatDate(dateString[, dateFormat, timeFormat, localeCode])  →  string
1–4 arguments

Parameters

Name Type Required Description
dateString string | date Yes The date to format, either a real date value or a parseable date string
dateFormat string No The date pattern. Letters are case-sensitive: MM is the month, mm the minutes. Some single letters, such as d, G or r, select a standard format
timeFormat string No A second pattern, whose output is appended after a space
localeCode string No The locale for month names, such as fr-FR

Example

%%=FormatDate("2026-01-15", "MM/dd/yyyy")=%%

Renders 01/15/2026.

A full timestamp fits in one pattern:

%%=FormatDate("2026-03-04 13:52:07", "yyyy-MM-dd HH:mm:ss")=%%

Renders 2026-03-04 13:52:07.

Return value

string — the formatted date. Called with only a date, it renders 3/4/2026 1:52:07 PM for 2026-03-04 13:52:07.

There is no empty-string failure value: input that cannot be read as a date is printed back (see below).

Behaviour

All rows below format 2026-03-04 13:52:07, a Wednesday, written as @d in the calls.

Letters are case-sensitive. MM is the month and mm the minutes, in the date pattern as well as in the time pattern:

Pattern Renders
yyyy-MM-dd HH:mm:ss 2026-03-04 13:52:07
yyyy-mm-dd hh:mm:ss 2026-52-04 01:52:07
mm, mmm, mmmm 52
MMMM March
MMM Mar
dd 04
DD 63 (day of the year)
DDDD 0063
yy, YY 26
yyyy, YYYY 2026
HH, hh, ss, tt 13, 01, 07, PM
gg AD
zz, zzz GMT, Z

Day names. ddd gives Wed (and Fri for December 25); dddd and ddddd both give Wednesday.

Single letters select standard formats.

Pattern Renders
d 3/4/2026
D Wednesday, March 4, 2026
M March 4
Y March 2026
f Wednesday, March 4, 2026 1:52 PM
F Wednesday, March 4, 2026 1:52:07 PM
g 3/4/2026 1:52 PM
G 3/4/2026 1:52:07 PM
o 2026-03-04T13:52:07.0000000+0000
r Wed, 04 Mar 2026 13:52:07 GMT
s 2026-03-04T13:52:07
t 1:52 PM
T 1:52:07 PM
u 2026-03-04 13:52:07Z
U Wednesday, March 4, 2026 1:52:07 PM

Unknown patterns fall back to a default. qqqq, l, iso and rfc each rendered 2026-03-04 13:52:07. L rendered 3 and S rendered 0.

The time pattern is appended after a space. FormatDate(@d, "yyyy-MM-dd", "HH:mm:ss") gives 2026-03-04 13:52:07. With an empty date pattern the space stays at the front: FormatDate(@d, "", "HH:mm:ss") gives ` 13:52:07, and ”” with mm, MM, ss, tt, yyyy or fff gives 52, 03, 07, PM, 2026 and 000. A lone h gives 1 and a lone s gives 7, while a lone t gave 2026-03-04 13:52:07`.

The locale changes month names, not the pattern meaning. FormatDate(@d, "MMMM", "", "fr-FR") gives mars with a trailing space from the empty time pattern. With D the result stays the day of the year (63 ) for fr-FR, fr_FR, ja-JP and a made-up zz-ZZ. No locale is rejected.

Input formats. ISO dates, US slash dates (3/4/2026, 03/04/2026 13:52:07) and date values such as a DateAdd result format as expected. A timestamp with an offset is converted: 2026-03-04T13:52:07.123-0700 with HH:mm:ss gives 20:52:07.

Unreadable input is printed back. not a date at all and the number 20260304 are returned unchanged, and so is 4 March 2026 1:52:07 PM, which did not parse. An empty string returns an empty string. Check the input before formatting it.

One to four arguments. An email with FormatDate() or with five arguments cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.

Show Next test script
<!-- Marketing Cloud Next test script for FormatDate. 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=[01/15/2026] got=[%%=FormatDate("2026-01-15","MM/dd/yyyy")=%%]</p>
<p>c2 expect=[2026] got=[%%=FormatDate("2026-03-04 13:52:07","yyyy")=%%]</p>
<p>c3 expect=[March] got=[%%=FormatDate("2026-03-04 13:52:07","MMMM")=%%]</p>
<p>c4 expect=[ 13:52:07] got=[%%=FormatDate("2026-03-04 13:52:07","","HH:mm:ss")=%%]</p>
<p>c5 expect=[2026-03-04 13:52:07|52] got=[%%=FormatDate("2026-03-04 13:52:07","yyyy-MM-dd HH:mm:ss")=%%|%%=FormatDate("2026-03-04 13:52:07","mm")=%%]</p>
<p>c6 expect=[2026-03-04 13:52:07] got=[%%=FormatDate("2026-03-04 13:52:07","yyyy-MM-dd","HH:mm:ss")=%%]</p>
<p>c7 expect=[March 2026|26|2026|52|52|52|March 4|63|0063|2026-52-04 01:52:07] got=[%%=FormatDate("2026-03-04 13:52:07","Y")=%%|%%=FormatDate("2026-03-04 13:52:07","YY")=%%|%%=FormatDate("2026-03-04 13:52:07","YYYY")=%%|%%=FormatDate("2026-03-04 13:52:07","mmmm")=%%|%%=FormatDate("2026-03-04 13:52:07","mmm")=%%|%%=FormatDate("2026-03-04 13:52:07","mm")=%%|%%=FormatDate("2026-03-04 13:52:07","m")=%%|%%=FormatDate("2026-03-04 13:52:07","DD")=%%|%%=FormatDate("2026-03-04 13:52:07","DDDD")=%%|%%=FormatDate("2026-03-04 13:52:07","yyyy-mm-dd hh:mm:ss")=%%]</p>
<p>c8 expect=[ 52| 03| 000] got=[%%=FormatDate("2026-03-04 13:52:07","","mm")=%%|%%=FormatDate("2026-03-04 13:52:07","","MM")=%%|%%=FormatDate("2026-03-04 13:52:07","","fff")=%%]</p>
<p>c9 expect=[3/4/2026|March 4] got=[%%=FormatDate("2026-03-04 13:52:07","d")=%%|%%=FormatDate("2026-03-04 13:52:07","M")=%%]</p>
<p>c10 expect=[Wednesday|Wednesday] got=[%%=FormatDate("2026-03-04 13:52:07","dddd")=%%|%%=FormatDate("2026-03-04 13:52:07","ddddd")=%%]</p>
<p>c11 expect=[Wed|Fri] got=[%%=FormatDate("2026-03-04 13:52:07","ddd")=%%|%%=FormatDate("2026-12-25","ddd")=%%]</p>
<p>c12 expect=[26|2026|03|Mar|March|04|AD] got=[%%=FormatDate("2026-03-04 13:52:07","yy")=%%|%%=FormatDate("2026-03-04 13:52:07","yyyy")=%%|%%=FormatDate("2026-03-04 13:52:07","MM")=%%|%%=FormatDate("2026-03-04 13:52:07","MMM")=%%|%%=FormatDate("2026-03-04 13:52:07","MMMM")=%%|%%=FormatDate("2026-03-04 13:52:07","dd")=%%|%%=FormatDate("2026-03-04 13:52:07","gg")=%%]</p>
<p>c13 expect=[13|01|07|PM|GMT|Z] got=[%%=FormatDate("2026-03-04 13:52:07","HH")=%%|%%=FormatDate("2026-03-04 13:52:07","hh")=%%|%%=FormatDate("2026-03-04 13:52:07","ss")=%%|%%=FormatDate("2026-03-04 13:52:07","tt")=%%|%%=FormatDate("2026-03-04 13:52:07","zz")=%%|%%=FormatDate("2026-03-04 13:52:07","zzz")=%%]</p>
<p>c14 expect=[ 07| PM| 2026] got=[%%=FormatDate("2026-03-04 13:52:07","","ss")=%%|%%=FormatDate("2026-03-04 13:52:07","","tt")=%%|%%=FormatDate("2026-03-04 13:52:07","","yyyy")=%%]</p>
<p>c15 expect=[Wednesday, March 4, 2026|Wednesday, March 4, 2026 1:52 PM|Wednesday, March 4, 2026 1:52:07 PM|3/4/2026 1:52 PM|3/4/2026 1:52:07 PM|2026-03-04T13:52:07.0000000+0000|Wed, 04 Mar 2026 13:52:07 GMT|2026-03-04T13:52:07|1:52 PM|1:52:07 PM|2026-03-04 13:52:07Z|Wednesday, March 4, 2026 1:52:07 PM] got=[%%=FormatDate("2026-03-04 13:52:07","D")=%%|%%=FormatDate("2026-03-04 13:52:07","f")=%%|%%=FormatDate("2026-03-04 13:52:07","F")=%%|%%=FormatDate("2026-03-04 13:52:07","g")=%%|%%=FormatDate("2026-03-04 13:52:07","G")=%%|%%=FormatDate("2026-03-04 13:52:07","o")=%%|%%=FormatDate("2026-03-04 13:52:07","r")=%%|%%=FormatDate("2026-03-04 13:52:07","s")=%%|%%=FormatDate("2026-03-04 13:52:07","t")=%%|%%=FormatDate("2026-03-04 13:52:07","T")=%%|%%=FormatDate("2026-03-04 13:52:07","u")=%%|%%=FormatDate("2026-03-04 13:52:07","U")=%%]</p>
<p>c16 expect=[2026-03-04 13:52:07|3|0|2026-03-04 13:52:07|2026-03-04 13:52:07] got=[%%=FormatDate("2026-03-04 13:52:07","l")=%%|%%=FormatDate("2026-03-04 13:52:07","L")=%%|%%=FormatDate("2026-03-04 13:52:07","S")=%%|%%=FormatDate("2026-03-04 13:52:07","iso")=%%|%%=FormatDate("2026-03-04 13:52:07","rfc")=%%]</p>
<p>c17 expect=[ 7|2026-03-04 13:52:07] got=[%%=FormatDate("2026-03-04 13:52:07","","s")=%%|%%=FormatDate("2026-03-04 13:52:07","","t")=%%]</p>
<p>c18 expect=[63 |63 |mars |63 |0 |0 ] got=[%%=FormatDate("2026-03-04 13:52:07","D","","fr-FR")=%%|%%=FormatDate("2026-03-04 13:52:07","D","","fr_FR")=%%|%%=FormatDate("2026-03-04 13:52:07","MMMM","","fr-FR")=%%|%%=FormatDate("2026-03-04 13:52:07","D","","ja-JP")=%%|%%=FormatDate("2026-03-04 13:52:07","S","","uk_UA")=%%|%%=FormatDate("2026-03-04 13:52:07","S","","en-US")=%%]</p>
<p>c19 expect=[63 ] got=[%%=FormatDate("2026-03-04 13:52:07","D","","zz-ZZ")=%%]</p>
<p>c20 expect=[2026-03-04 13:52:07] got=[%%=FormatDate("2026-03-04 13:52:07","qqqq")=%%]</p>
<p>c21 expect=[not a date at all|] got=[%%=FormatDate("not a date at all","yyyy")=%%|%%=FormatDate("","yyyy")=%%]</p>
<p>c22 expect=[2026-03-04 20:52:07|2026-03-04 00:00:00|2026-03-04|2026-03-04 13:52:07|4 March 2026 1:52:07 PM] got=[%%=FormatDate("2026-03-04T13:52:07.123-0700","yyyy-MM-dd","HH:mm:ss")=%%|%%=FormatDate("2026-03-04","yyyy-MM-dd","HH:mm:ss")=%%|%%=FormatDate("3/4/2026","yyyy-MM-dd")=%%|%%=FormatDate("03/04/2026 13:52:07","yyyy-MM-dd","HH:mm:ss")=%%|%%=FormatDate("4 March 2026 1:52:07 PM","yyyy-MM-dd","HH:mm:ss")=%%]</p>
<p>c23 expect=[10|2026-03-04] got=[%%=Length(FormatDate(DateAdd(Now(),1,"D"),"yyyy-MM-dd"))=%%|%%=FormatDate(DateAdd("2026-03-04",0,"D"),"yyyy-MM-dd")=%%]</p>
<p>c24 expect=[20260304] got=[%%=FormatDate(20260304,"yyyy")=%%]</p>
<p>c25 expect=[3/4/2026 1:52:07 PM] got=[%%=FormatDate("2026-03-04 13:52:07")=%%]</p>
<p>c26 expect=[ 1] got=[%%=FormatDate("2026-03-04 13:52:07","","h")=%%]</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 save is rejected (HTTP 400) -->
%%=FormatDate()=%%

<!-- email 2: expect that the save is rejected (HTTP 400) -->
%%=FormatDate("2026-03-04 13:52:07","D","","en-US","extra")=%%

Differs from official docs

  • The reference’s own input string is not parsed. All usage examples, the Next one included, format 5 August 2024 1:41:23 PM. In Next, 4 March 2026 1:52:07 PM was returned unchanged, as was any other text that is not a date, without an error. Card
  • Locale formats do not work. The reference shows D as a long date per locale and S / L with a locale code as that locale’s short and long date. In Next, D with fr-FR gave 63 (day of the year) and S with uk_UA gave 0 . Card
  • o carries an offset. The reference’s example for o ends in seven fractional digits. In Next it ended in .0000000+0000. Card

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 67.0

See also