Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-41912

CAST('HH:MM:SS' AS DATE) parses the hour as the year; casting through TIME gives a different result

    XMLWordPrintable

Details

    Description

      Casting a valid TIME string directly to DATE does not convert the time-of-day: the text is re-parsed as a date and the leading digits (the hours) become the year. Going through TIME first gives a completely different, sane result, so the same input reaches DATE by two different rules.

      Reproduced on 10.11.19 and on 13.1 (debug builds); the "through TIME" values below were measured on 2026-10-29 and track now + the TIME value:

      SELECT CAST('25:00:00' AS DATE);                 -- 2025-00-00
      SELECT CAST(CAST('25:00:00' AS TIME) AS DATE);   -- 2026-10-30 (now + 25 hours)
       
      SELECT CAST('100:00:00' AS DATE);                -- 0100-00-00
      SELECT CAST(CAST('100:00:00' AS TIME) AS DATE);  -- 2026-11-02 (now + 100 hours)

      '25:00:00' is a valid TIME value, but CAST('25:00:00' AS DATE) builds the zero-month/zero-day date 2025-00-00 out of the hour digits, while casting the same string to TIME and then to DATE interprets it as an offset from the current time and returns a real date. Expected: both paths agree.

      MySQL 8 returns NULL for CAST('25:00:00' AS DATE).

      Related: MDEV-4882 (TIME to DATETIME conversion differences).

      Attachments

        Issue Links

          Activity

            People

              raghunandan.bhat Raghunandan Bhat
              chunlingqin chunlingqin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  Remaining:
                  Remaining Estimate - 2d
                  2d
                  Logged:
                  Time Spent - Not Specified
                  Not Specified

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.