TO_DATETIME
Description
Converts a string in a recognized date/time format into a Datetime value. The result is returned in GMT. If the input string cannot be parsed, an error is thrown.
Syntax
TO_DATETIME(string) -> Datetime
Parameters
| Parameter | Data Type | Required | Description |
|---|---|---|---|
| string | String | Yes | The string to convert into a Datetime, provided in a recognized date/time format. |
Example
TO_DATETIME("2002-10-09T19:00:00-05:00")
-- Returns 2002-10-10T00:00:00.000Z as a Datetime in GMT.Tips
Returns null for blank or null inputs.
Primarily parses using Salesforce's built-in Datetime.parse().
If primary parsing fails, falls back to parsing via JSON deserialization.
Throws an ApplicationException if all parsing attempts fail.