Skip to main content

isDateTime

Tests if the input string can be parsed to create a datetime object. Returns a Boolean true or false.

The first parameter takes a string, and the second takes a format pattern for parsing. If the second parameter is unspecified, the function tries to parse using the default pattern 'yyyy-MM-ddTHH:mm:ss'.

To create a datetime object from a string, use parseDateTime instead.

Parameters

  • DATETIME STRING (string)

    The input string to check (e.g. '25 Dec 2018').

  • INPUT FORMAT (string)

    Optional. The format pattern for parsing the input string (e.g. 'dd-MM-yyyy').

    Note

    For more about pattern letters, see the section Patterns for Formatting and Parsing on Oracle’s documentation site. We refer you to that section only; we don't support predefined formatters such as those defined elsewhere on that page.

    Alternatively, enter a locale to use the format pattern for a specific region.

    Default: 'yyyy-MM-ddTHH:mm:ss' (this pattern follows the international standard ISO-8601)

Examples

The function uses 'yyyy-MM-ddTHH:mm:ss' to parse when the second parameter is unspecified.

ATL in Script

Result

[[isDateTime('2019-03-18')]]

true

[[isDateTime('18-03-2018')]]

false

[[isDateTime('08:00:00')]]

true

[[isDateTime('0800')]]

false

[[isDateTime('2019-03-18T08:00:00')]]

true

[[isDateTime('2019-03-18 08:00:00')]]

false

These examples show how to use the second parameter:

ATL in Script

Result

[[isDateTime('18/03/19', 'dd/MM/yy')]]

true

[[isDateTime('18/03/19', 'dd/MM/yyyy')]]

false

[[isDateTime('8 am', 'H \'am\'')]]

true

[[isDateTime('8.00 am', 'H \'am\'')]]

false

[[isDateTime('18-03-2019 23:00:00', 'dd-MM-yyyy HH:mm:ss')]]

true

[[isDateTime('18-03-2019 23:00:00', 'dd-MMM-yy HH:mm:ss')]]

false

Using isDateTime in a conditional statement

The isDateTime function does NOT parse a string to create a datetime object — it just checks if Studio can do so. However, because the function returns a Boolean true or false, you can use it conditional statements.

Assume a "Describe the Table" project with this data:

Employee

LastLogin

Row 1

Andy

2019-03-18T17:15:17

Row 2

Sandra

2017-04-17 18:32:33

The LastLogin value for Row 1 is in an automatically recognized datetime pattern ('yyyy-MM-ddTHH:mm:ss'), so Studio treats it as a datetime object. The same is not true for the Row 2 value.

Suppose that you want your narrative to display the LastLogin value only when it's automatically recognized as a datetime object, and you want an alternative sentence when the value is not automatically recognized.

Here is how to use isDateTime in a conditional statement to achieve the effect:

[[

if(isDateTime(LastLogin))
{[[Employee]]'s last login was at [[formatDateTime(LastLogin,'HH:mm \'on\' dd/MM/yyyy')]].}

else
{[[Employee]]'s last login is unknown.}

]]

The printed result for Row 1 is:

Andy's last login was at 17:15 on 18/03/2019.

The printed result for Row 2 is:

Sandra's last login is unknown.