Altair® Monarch®

 

Function: Ctod

Description

Converts a string to a date.

Syntax

Ctod(string[,date format[,extraction format]])

Arguments

string can be a constant, a character field, an expression that results in a string or a function that returns a string.

The optional date format parameter tells Monarch Classic how to interpret the date. Valid options for this parameter are "m/d/y", "d/m/y" and "y/m/d" (the quotation marks are required).

The optional date/time extraction pattern parameter specifies the "date/time extraction pattern". Possible extraction patterns are as follows:

 

Pattern

Meaning

"D"

Extract a date.

"DT"

Extract a date followed by a time.

"T"

Extract a time.

"TD"

Extract a time followed by a date.

 

More than one extraction pattern may be combined to form a list of extraction patterns. For example: "D,DT" means "extract a date OR a date followed by a time".

Extraction patterns are not case-sensitive.

If an explicit extraction pattern is not provided to Ctod, it uses the default extraction patterns from the model or registry.

Return value

This function returns a date in the form YYYYMMDD.

Calculated field example

Monarch Classic provides a date format setting that determines how date fields are interpreted when extracted from a report file. But some reports contain dates in more than one format. To allow for multiple date formats, the Ctod function accepts an optional type parameter that lets you specify how to interpret the date.

For example, let's say a report has two dates. The Rpt_date field values are expressed as 03/08/2001 (MDY format) but the Ship_date field values is expressed as 2001/03/08 (YMD format).

To extract both dates, set the Date Format setting to MDY. Monarch Classic will interpret the Rpt_date field, but will extract the Ship_date (YMD) as a character field. To convert the character field to a date field, use the following calculated field expression: Ctod(Ship_date,"y/m/d")

The "y/m/d" parameter tells Monarch Classic how to interpret the date, in this case as YMD format. Valid options for this parameter are "m/d/y", "d/m/y" and "y/m/d" (the quotation marks are required).

Filter/Find example

Records with a Hire_date field containing dates prior to 19800601 (June 01, 1980) can be selected or found using the expression: Hire_date<=Ctod("June 01, 1980")