IBM Support

Casting a String to Date fails with error -1218

Troubleshooting


Problem

This article describes a known problem which causes an error -1218 when casting a string containing a datetime value to date.

Resolving The Problem


PROBLEM

When you try to cast a string which has a datetime value to date, you receive the following error:

    1218:String to date conversion error

SCOPE

The following products and platforms are affected:

Product Name
Product Version(s)
Hardware Vendor
Operating System
IBM® Informix® Dynamic Server™
  • 7.31.UD7 and higher
  • 9.30.UC7
  • 9.40.UC3 and higher
  • 10.00.UCx
  • ALL
    ALL


    CAUSE

    This is the current expected behavior of the product. If the string does not contain a valid date value, you get error -1218.


    SOLUTION

    To cast a string which contains a datetime value to date, you should cast it to datetime, or cast it to datetime first, and then to date.

    Example:
      You want to update a column c1 of type date in a table t1.

      The following syntax will return error - 1218:
        $update t1 set c1 = ('2003-02-22 05:58:44.000')::DATE


      The following syntax is correct and will not return any errors:
        $update t1 set c1 = ('2003-02-22 05:58:44.000')::DATETIME YEAR TO FRACTION

        $update t1 set c1 = ('2003-02-22 05:58:44.000')::DATETIME YEAR TO FRACTION::DATE

    [{"Product":{"code":"SSGU8G","label":"Informix Servers"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF025","label":"Platform Independent"},{"code":"PF008","label":"DYNIX\/ptx"},{"code":"PF010","label":"HP-UX"},{"code":"PF015","label":"IRIX"},{"code":"PF016","label":"Linux"},{"code":"PF026","label":"Reliant UNIX"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"7.3;9.2;9.3;9.4;10.0","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

    Document Information

    Modified date:
    16 June 2018

    UID

    swg21199755