You use strToDateTime in OCL when you need to convert a text value that represents both a date and a time into a DateTime value.
What it does
strToDateTime converts a string to a DateTime value by using the CLR System.Convert.ToDateTime() conversion.
Use this operator when the source value contains a date and time and the receiving expression requires a DateTime value. For a date-only result, use strToDate instead.
When to use it
Use strToDateTime for text values such as an imported or entered date-and-time value when you need to work with it as a DateTime value in an OCL expression.
For example, if a string value represents when an appointment starts, convert that string with strToDateTime before using it where a DateTime value is required.
DateTime compared with Date
| Requirement | Operator | Result |
|---|---|---|
| You need the date and time represented by a string. | strToDateTime
|
A DateTime value. |
| You need only the date portion of a string value. | strToDate | A Date value. The conversion first uses System.Convert.ToDateTime(), then extracts the date portion.
|
Input considerations
The conversion is performed by the CLR System.Convert.ToDateTime() method. Ensure that the source string is a date-and-time representation that this conversion can interpret in the environment where the expression runs.
If your source is text and may not represent a valid date and time, define and apply validation appropriate to that source before relying on the converted value. See Parse for the related parsing operator.
