FormatDate()

Formats a string as a date value.

Availability

<table> <tr> <td>Marketing Cloud Engagement</td> <td>✅ Yes</td> </tr> <tr> <td>Marketing Cloud Next</td> <td>✅ Yes, <a href="#differences-between-marketing-cloud-engagement-and-marketing-cloud-next">with some differences</a></td> </tr> </table>

This function became available in Marketing Cloud Next during the Summer ’26 release (API version 67.0).

Differences Between Marketing Cloud Engagement and Marketing Cloud Next

In Marketing Cloud Engagement, this function uses standard .NET date and time formatting libraries. In Marketing Cloud Next, this function uses the Java SimpleDateFormat class, which uses different formatting strings.

In Marketing Cloud Next, if you don’t specify a value for the dateFormat parameter, the function returns a string formatted with the G standard format. This format uses a combination of a short date value and a long time value. For example, in the en_US locale, this function outputs a timestamp that’s similar to this example: 5/15/2026 1:23:45 PM.

Syntax

FormatDate(dateString, dateFormat, timeFormat, localeCode)

The FormatDate() function has these parameters:

  • dateString (string): Required. The date string that you want to format.
  • dateFormat (string): A string that represents the format to apply to the date.
  • timeFormat (string): A string that represents the format to apply to the time.
  • localeCode (string): The locale code to use when formatting the date.

Input Date Formats

In Marketing Cloud Engagement, you can specify a date in these formats.

Description Format Example
ISO timestamp yyyy-MM-dd'T'HH:mm:ss.fffzzz 2026-08-05T13:45:30.123-0700
Japanese notation yyyy '年' M '月' d '日' 2026 年 8 月 5 日
Korean notation yyyy'년' M'월' d'일' 2026년 8월 5일
Sortable date yyyy-MM-dd 2026-08-05
Sortable date and time yyyy-MM-dd HH:mm:ss 2026-08-05 13:45:30
US Customary date (non-zero-padded) M/d/yyyy 8/5/2026
US Customary date (zero-padded) MM/dd/yyyy 08/05/2026
US Customary date and time (12-hour time, non-zero-padded) M/d/yyyy h:mm:ss tt 8/5/2026 1:45:30
US Customary date and time (24-hour time, zero-padded) MM/dd/yyyy HH:mm:ss 08/05/2026 13:45:30
US Customary date and time with time zone MM/dd/yyyy HH:mm:ss fff 08/05/2026 13:45:30 -0700

In Marketing Cloud Next, you can specify a date in these formats.

Description Format Example
ISO timestamp yyyy-MM-dd'T'HH:mm:ss.SSSZ 2026-08-05T13:45:30.123-0700
Sortable date yyyy-MM-dd 2026-08-05
Sortable date and time yyyy-MM-dd HH:mm:ss 2026-08-05 13:45:30
US Customary date (zero-padded) MM/dd/yyyy 08/05/2026
US Customary date and time (24-hour time, zero-padded) MM/dd/yyyy HH:mm:ss 08/05/2026 13:45:30
US Customary date and time with time zone MM/dd/yyyy HH:mm:ss ZZZ 08/05/2026 13:45:30 -0700

Usage

To use this function, supply it with a date to format. If you don’t pass any other parameters, the function formats the date string according to the locale settings for your Marketing Cloud Engagement business unit or your Marketing Cloud Next org. This example formats a date string to use the default locale setting for an account based in the United States.

%%[
  Var @now, @dateString
  Set @now = "5 August 2024 1:41:23 PM"
  Set @dateString = FormatDate(@now)
]%%
<p>Date and time formatted for your locale: %%=v(@dateString)=%%</p>

The function outputs the date and time.

Date and time formatted for your locale: 8/5/2024 1:41:23 PM

Pre-Defined Date Formats

The FormatDate() function can format a date string into one of several predefined formats. This table lists the formats that are available in both Marketing Cloud Engagement and Marketing Cloud Next. Because the output value can vary based on the locale, this table includes example values for the en_US, fr_FR, and ja_JP locales.

Description Format String Examples
Short date d <ul><li>(en_US) 8/5/2026</li><li>(fr_FR) 05/08/2026</li><li>(ja_JP) 2026/08/05</li></ul>
Long date D <ul><li>(en_US) Wednesday, August 5, 2026</li><li>(fr_FR) mercredi 5 août 2026</li><li>(ja_JP) 2026 年 8 月 5 日</li></ul>
Long date and short time f <ul><li>(en_US) Wednesday, August 5, 2026 1:45 PM</li><li>(fr_FR) mercredi 5 août 2026 13:45</li><li>(ja_JP) 2026 年 8 月 5 日 13:45</li></ul>
Long date and long time F <ul><li>(en_US) Wednesday, August 5, 2026 1:45:30 PM</li><li>(fr_FR) mercredi 5 août 2026 13:45:30</li><li>(ja_JP) 2026 年 8 月 5 日 13:45:30</li></ul>
General date with short time g <ul><li>(en_US) 8/5/2026 1:45 PM</li><li>(fr_FR) 05/08/2026 13:45</li><li>(ja_JP) 2026/08/05 13:45</li></ul>
General date with long time G <ul><li>(en_US) 8/5/2026 1:45:30 PM</li><li>(fr_FR) 05/08/2026 13:45:30</li><li>(ja_JP) 2026/08/05 13:45:30</li></ul>
Month and day m or M <ul><li>(en_US) August 5</li><li>(fr_FR) 5 août</li><li>(ja_JP) 8 月 5 日</li></ul>
Round-trip date and time o or O <ul><li>(en_US) 2026-08-05T13:45:30.1230000</li><li>(fr_FR) 2026-08-05T13:45:30.1230000</li><li>(ja_JP) 2026-08-05T13:45:30.1230000</li></ul>
RFC1123 date and time r or R <ul><li>(en_US) Wed, 05 Aug 2026 13:45:30 GMT</li><li>(fr_FR) Wed, 05 Aug 2026 13:45:30 GMT</li><li>(ja_JP) Wed, 05 Aug 2026 13:45:30 GMT</li></ul>
Sortable date and time s <ul><li>(en_US) 2026-08-05T13:45:30</li><li>(fr_FR) 2026-08-05T13:45:30</li><li>(ja_JP) 2026-08-05T13:45:30</li></ul>
Short time t <ul><li>(en_US) 1:45 PM</li><li>(fr_FR) 13:45</li><li>(ja_JP) 13:45</li></ul>
Long time T <ul><li>(en_US) 1:45:30 PM</li><li>(fr_FR) 13:45:30</li><li>(ja_JP) 13:45:30</li></ul>
Universal sortable date and time u <ul><li>(en_US) 2026-08-05 13:45:30Z</li><li>(fr_FR) 2026-08-05 13:45:30Z</li><li>(ja_JP) 2026-08-05 13:45:30Z</li></ul>
Universal full date and time U <ul><li>(en_US) Wednesday, August 5, 2026 1:45:30 PM</li><li>(fr_FR) mercredi 5 août 2026 13:45:30</li><li>(ja_JP) 2026 年 8 月 5 日 13:45:30</li></ul>
Month and year y or Y <ul><li>(en_US) August 2026</li><li>(fr_FR) août 2026</li><li>(ja_JP) 2026 年 8 月</li></ul>

Custom Date Formats

You can format a date string using a custom format by passing a string that specifies the format. The strings that you use vary depending on whether you use Marketing Cloud Engagement or Marketing Cloud Next.

Day and Date Format Strings

Description Example String (MC Engagement) String (MC Next)
Full day name Monday dddd EEEE
Abbreviated day name Mon ddd EEE
Date (zero-padded) 05 dd dd
Date (non-zero-padded) 5 d d
Day number in week 1 (not available) u

Month Format Strings

Description Example String (MC Engagement) String (MC Next)
Full month name August MMMM MMMMM
Abbreviated month name Aug MMM MMM
Month number (zero-padded) 08 MM MM
Month number (non-zero-padded) 8 M M

Year Format Strings

Description Example String (MC Engagement) String (MC Next)
Full year number 2026 yyyy yyyy
Last two digits of year 26 yy yy
Calendar era AD gg G

Time Format Strings

Description Example String (MC Engagement) String (MC Next)
Hour (24-hour, zero-padded) 13 HH HH
Hour (24-hour, non-zero-padded) 13 H H
Hour (12-hour, zero-padded) 01 hh hh
Hour (12-hour, non-zero-padded) 1 h h
Minute (zero-padded) 05 mm mm
Minute (non-zero-padded) 5 m m
Second (zero-padded) 09 ss ss
Second (non-zero-padded) 9 s s
Millisecond 423 fff S
AM/PM marker (two letter) PM tt a
AM/PM marker (first letter only) P t (not available)
Time zone name UTC (not available) z
Time zone offset (hours and minutes, zero-padded) -0800 zzz Z
Time zone offset (hours only, zero-padded) -08 zz X
Time zone offset (hours only, non-zero-padded) -8 z X

Usage Example

This example shows how to format the date to include the full name of the day, the full name of the month, the date without a leading zero, and the year. It also shows the time in a 24-hour format, including hours, minutes, and seconds. This example works with Marketing Cloud Engagement.

%%[
  Var @now, @dateString
  Set @now = "5 August 2024 1:41:23 PM"
  Set @dateString = FormatDate(@now, "dddd, MMMM d yyyy", "HH:mm:ss")
]%%
<p>Date and time with a custom format: %%=v(@dateString)=%%</p>

In Marketing Cloud Next, use this example instead.

%%[
  Var @now, @dateString
  Set @now = "5 August 2024 1:41:23 PM"
  Set @dateString = FormatDate(@now, "EEEE, MMMMM d yyyy", "HH:mm:ss")
]%%
<p>Date and time with a custom format: %%=v(@dateString)=%%</p>

The function outputs the date and time using the format that you specified.

Date and time with a custom format: Monday, August 5 2024 13:41:23

Formatting for a Different Locale

You can format a date string into a format that aligns with the common notation for a locale by passing S or L for the dateFormat parameter, and the locale code for the localeCode parameter.

%%[
  Var @now,
      @dateStringUA_S,
      @dateStringUA_L,
      @dateStringJP_S,
      @dateStringJP_L,
      @dateStringFR_S,
      @dateStringFR_L

  Set @now = "5 August 2024 1:41:23 PM"
  Set @dateStringUA_S = FormatDate(@now, "S", , "uk_UA")
  Set @dateStringUA_L = FormatDate(@now, "L", , "uk_UA")
  Set @dateStringJP_S = FormatDate(@now, "S", , "ja_JP")
  Set @dateStringJP_L = FormatDate(@now, "L", , "ja_JP")
  Set @dateStringFR_S = FormatDate(@now, "S", , "fr_CA")
  Set @dateStringFR_L = FormatDate(@now, "L", , "fr_CA")
]%%

<p>Short-form date for the uk_UA locale (Ukrainian): %%=v(@dateStringUA_S)=%%</p>
<p>Long-form date for the uk_UA locale (Ukrainian): %%=v(@dateStringUA_L)=%%</p>
<p>Short-form date for the ja_JP locale (Japanese): %%=v(@dateStringJP_S)=%%</p>
<p>Long-form date for the ja_JP locale (Japanese): %%=v(@dateStringJP_L)=%%</p>
<p>Short-form date for the fr_CA locale (Canadian French): %%=v(@dateStringFR_S)=%%</p>
<p>Long-form date for the fr_CA locale (Canadian French): %%=v(@dateStringFR_L)=%%</p>

The code outputs the short- and long-form date strings for the specified locales.

Short-form date for the uk_UA locale (Ukrainian): 05.08.2024

Long-form date for the uk_UA locale (Ukrainian): 5 серпня 2024 р.

Short-form date for the ja_JP locale (Japanese): 2024/08/05

Long-form date for the ja_JP locale (Japanese): 2024年8月5日

Short-form date for the fr_CA locale (Canadian French): 2024-08-05

Long-form date for the fr_CA locale (Canadian French): 5 août 2024