Skip to content

tryParse

Parses the specified string like DateTimeOffset.parse, but returns null when the text is not a valid date, in both server workflow scripts and browser form scripts.

1
DateTimeOffset.tryParse(val: string, format?: string):( DateTimeOffset | null )

Parameters

string val
    A string representing the date and time.

string format optional
    The exact format, as in DateTimeOffset.parse.

Returns

The parsed value, or null.

Examples

Read an optional date from a request

1
2
3
4
5
var dueDate = DateTimeOffset.tryParse($Xml.Evaluate('Request/DueDate'));

if (dueDate == null) {
    throw new Error('The due date is not valid.');
}

See Also