TO_DATE

Description

Converts a String or Datetime value into a Date by extracting the calendar date from the input. If the input cannot be parsed, an error is thrown.

Syntax

TO_DATE(string/datetime) -> Date

Parameters

ParameterData TypeRequiredDescription
string/datetimeString/DatetimeYesThe value to convert to a Date.

Examples

TO_DATE("2005-11-15")
-- Returns "2005-11-15" as a Date.
TO_DATE(NOW())
-- Returns today's Date extracted from the current Datetime.

Tips

  • Returns null for blank or null inputs.

  • Primarily parses using Salesforce's built-in Date.parse().

  • If primary parsing fails, attempts parsing via JSON deserialization.

  • As a final attempt, replaces dashes (-) with slashes (/) and retries parsing.

  • Throws an ApplicationException if all parsing attempts fail.

Related Formula