FormatDate()

Formats a string as a date value.

The FormatDate() function has four 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, such as ddddd, d MMMM yyyy. You can also pass these strings.
    • S – Formats the date using the short-form format for the locale that you specify in the localeCode parameter.
    • L – Formats the date using the long-form format for the locale that you specify in the localeCode parameter.
    • ISO – Formats the date and time in an ISO-8601-compliant format.
    • RFC – Formats the date and time in an RFC-1123-compliant format.
  • timeFormat (string): A string that represents the format to apply to the time, such as H:mm:ss tt.
  • localeCode (string): The locale code to use when formatting the date, such as ja_JP.

You can specify a date string in several formats, including these formats.

  • ISO 8601 timestamp: 2024-08-05T13:41:23-06:00
  • ISO 8601 date: 2024-08-05
  • US date and time notation: 8/5/2024 1:41 PM
  • Long-form notation: 5 August 2024 or August 5, 2024
  • Date and time: 2024-08-05 1:41:23 PM
  • Time only: 1:41 PM
  • Chinese and Japanese notation: 2024 年 8 月 5 日
  • Korean notation: 2024년 8월 5일

The function doesn’t support these formats.

  • Dates in which the day includes an ordinal suffix, such as August 5th, 2024 or 5th August 2024.
  • Little-endian numeral notation, such as 5/8/2024 to represent the fifth day of August 2024.
  • Month names in languages other than English, such as 5 août 2024.
  • Dates that include any numerals other than Western Arabic numerals, such as ٢٠٢٣/٨/٥.
  • Dates based on any calendar system other than the Gregorian calendar, such as 18 Av, 5783 or 18 Muharram, 1445.

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. This example formats a date string to use the default locale setting for an account based in the United States.

The function outputs the date and time using the locale settings for the current Marketing Cloud Engagement account.

You can format a date string using a custom format by passing a string that specifies the format. This table shows the formatting elements that you can pass in a custom date string.

Year (Example: 2024)Month (Example: August)Date (Example: Saturday, August 06)Hours (Example: 20)Minutes (Example: :00)Seconds (Example: :05)AM/PM (Example: PM)Offset (Example: -6:00)
y = 24M = 8d = 6h = 8m = 0s = 5t = Pz = -6
yy = 24MM = 08dd = 06hh = 08mm = 00ss = 05tt = PMzz = -06
yyy = 2024MMM = Augdddd = SatH = 8---zzz = -06:00
yyyy = 2024MMMM = Augustddddd = SaturdayHH = 20----

This example shows how to format the date to include the full name of the day ("ddddd"), the full name of the month ("MMMM"), the date without a leading zero ("d"), and the year ("yyyy"). It also shows the time in a 24-hour format, including hours, minutes, and seconds ("h:mm").

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

The FormatDate() function can format a date string into one of several predefined formats. This example converts a string into an ISO-8601-compliant timestamp.

The function outputs the timestamp in ISO 8601 format.

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.

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