The mi_string_to_datetime() function

The mi_string_to_datetime() function converts a text (string) representation of a date, time, or date and time value to its internal (binary) DATETIME representation.

Syntax

mi_datetime *mi_string_to_datetime(dt_string, type_range)
   mi_string *dt_string;
   mi_string *type_range;
dt_string
A pointer to the date, time, or date and time string to convert to its internal DATETIME format.
type_range
A pointer to a string that specifies the range of DATETIME qualifiers in the date, time, or date and time string that dt_string references.
Valid in client LIBMI application? Valid in user-defined routine?
Yes Yes

Usage

The mi_string_to_datetime() function converts the date and/or time string that dt_string references to its internal DATETIME value. An internal DATETIME value is the format that the database server uses to store a value in a DATETIME column of the database.

The date and/or time string that dt_string references has the following fixed ANSI SQL format:
"YYYY-MM-DD HH:mm:SS.FFFFF"
YYYY
The 4-digit year.
MM
The 2-digit month.
DD
The 2-digit day.
HH
The 2-digit hour.
mm
The 2-digit minute.
SS
The 2-digit second.
FFFFF
The fraction of a second, in which the date, time, or date and time qualifier specifies the number of digits, with a maximum precision of five digits.
Server only: When you call mi_string_to_datetime() in a C UDR, this date and/or time string can contain only a subset of this range. In this case, the type_range argument must specify the range of qualifiers that the date and/or time string contains. This qualifier range begins with the keyword datetime and is followed by the range of qualifiers for the value in the dt_string. For example, the following call to mi_string_to_datetime() converts the date 01/31/07 and a time of 10:30 A.M. to its internal DATETIME format:
mi_datetime *internal_dt;
...
internal_dt = mi_string_to_datetime(
            "2007-01-31 10:30",
            "datetime year to minute");
If the type_range argument is a NULL-valued pointer, the mi_string_to_datetime() function assumes a default qualifier range of:
"datetime year to second"
Client only: When you call mi_string_to_datetime() in a client LIBMI application, this date and/or time string must contain the full range of qualifiers. The type_range argument must also specify the full range. For example, the following call to mi_string_to_datetime() converts the date 05/31/07 and a time of 8:52 a.m. to its internal DATETIME format:
mi_datetime *internal_dt;
...
internal_dt = mi_string_to_datetime(
            "2007-05-31 08:52:12",
            "datetime year to second");
Important: The mi_string_to_datetime() function replaces the mi_datetime_to_binary() function for string-to-internal-DATETIME conversion in DataBlade® API modules.

For GLS, the mi_string_to_datetime() function does not accept the date and/or time string in the date and time formats of the current processing locale.

For more information about how to convert date and/or time strings to internal DATETIME format, see the Informix® DataBlade® API Programmer's Guide.

Return values

An mi_datetime pointer
A pointer to the internal DATETIME representation that mi_string_to_datetime() has created.
NULL
The function was not successful.