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 your locale, or the locale that you specify for the cultureCode parameter.
    • L - Formats the date using the long-form format for your locale, or the locale that you specify for the cultureCode parameter.
    • ISO - Formats the date and time using an ISO-8601-compliant format.
    • RFC - Formats the date and time using an RFC-1123-compliant format.
  • timeFormat (string): A string that represents the format to apply to the time, such as "H:mm tt".
  • cultureCode (string): The culture code to use when formatting the date, such as "ja_JP".

You can specify a date string in several formats, including:

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

The function doesn’t support these formats:

  • Dates in which the day includes an ordinal suffix, such as August 5th, 2023 or 5th August 2023.
  • Little-endian numeral notation, such as 5/8/2023 to represent the 5th of August, 2023.
  • Month names in languages other than English, such as 5 août 2023.
  • 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: 2011)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 = 11M = 8d = 6h = 8m = 0s = 5t = Pz = -6
yy = 11MM = 08dd = 06hh = 08mm = 00ss = 05tt = PMzz = -06
yyy = 2011MMM = Augdddd = SatH = 8---zzz = -06:00
yyyy = 2011MMMM = 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 24-hour format, including hours, minutes, and seconds ("h:mm").

The function outputs the date and time using the format 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 specific locale by passing the cultureCode parameter.

The function outputs the date using a format common in the de_DE (Germany) locale.

The dateFormat and timeFormat parameters take precedence over the cultureCode parameter in terms of date formatting. If you specify all three parameters, the cultureCode parameter is used to translate the names of the days and months. This example includes all three parameters.

The function outputs the date and time using the date and time formats specified, and with language elements from the specified locale.