🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators strToDateTime
This page was created by Stephanie on 2025-01-09. Last edited by Wikiadmin on 2026-08-17.

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.

Syntax

strToDateTime() : DateTime

Examples

The following examples demonstrate strToDateTime() with various input formats:

Expression Result
'2025-01-15T14:30:00'.strToDateTime() 1/15/2025 2:30:00 PM
'2025-01-15'.strToDateTime() 1/15/2025 12:00 AM
'01/15/2025 09:00'.strToDateTime() 1/15/2025 9:00 AM
'invalid'.strToDateTime() error

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.

See also