Skip to content

CAST of a number to DATETIME or DATE throws a TypeError: CAST(19961121194027 AS DATETIME) #2853

Open

Description

@mathiasrw

CAST of a number to DATETIME or DATE throws a TypeError. MySQL reads such a number as YYYYMMDDhhmmss or YYYYMMDD.

Seen in the MySQL server tests run (alasql-mysqltest): 12 statements in 6 files, for example SELECT CAST(NULLIF(19961121194027, 0) AS DATETIME) AS dt in func_if.test. Reproduced with alasql 4.21.0:

alasql('SELECT CAST(19961121194027 AS DATETIME) AS d');   // TypeError: val.substr is not a function
alasql('SELECT CAST(20200102 AS DATE) AS d');             // TypeError: val.substr is not a function
alasql("SELECT CAST('1996-11-21 19:40:27' AS DATETIME) AS d");   // works

Expected (MySQL): 1996-11-21 19:40:27 and 2020-01-02. At least an error that says the value is not a date, not a TypeError.

Breaking?

No. Today it throws.

Related: #2804 (CAST to DATE of text gives a two-digit year).

Activity

  1. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I'd like to work on this one.

  2. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I've opened a PR for this: #2988

  3. added this to the v5.0.0 milestone on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions