Skip to content
Patrick van Kleef edited this page Oct 8, 2024 · 1 revision

NAME

stringdate - Convert a string to a datetime

SYNOPSIS

**stringdate(in *str *** varchar);

DESCRIPTION

stringdate converts dates and timestamps from text to the internal DATETIME type.

The external format is: YYYY.MM.DD hh:mm.ss uuuuuu where uuuuuu represents number of microseconds.

If trailing parts are omitted from the string given to stringdate, they are assumed to be zero. The three first parts are mandatory. Note that use of

cast (x as datetime)

is preferred over this function.

PARAMETERS

str

A **varchar ** date in human-readable (external) format.

ERRORS

Table 1. Errors signalled by datestring and stringdate

SQLState Error Code Error Text Description
22007 DT006 Cannot convert <offending string> to datetime
22002 DT007 Nulls not allowed as parameters to stringdate

EXAMPLES

Example 1. Stringdate example with datestring_GMT

We are at central european time zone CET(GMT+1).

SQL> use Demo;

 Done. -- 3 msec.
 SQL> select (datestring_GMT (stringdate (2000-01-01 22:00)));
 callret
 VARCHAR
 _______________________________________________________________________________

 2000-01-01 21:00:00.000000

 1 Rows. -- 45 msec.
 SQL> select left (datestring(ShippedDate), 10) from Orders
    where ShippedDate > stringdate (1996.6.3);
 callret
 VARCHAR
 _______________________________________________________________________________

 1996-06-04
 1996-06-04
 1996-06-05
 1996-06-05
 1996-06-05

 5 Rows. -- 3 msec.

SEE ALSO

**datestring **

The discussion of TIMESTAMP datatype in section Database Concepts of the documentation.