Skip to content

bug: STR_TO_DATE() Function does not work well #975

@davidshiz

Description

@davidshiz

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

STR_TO_DATE() Function return wrong results
as follows

mysql> SELECT date, format, STR_TO_DATE(date, format) as str_to_date FROM t1;
+---------------+---------------+----------------------------+
| date          | format        | str_to_date                |
+---------------+---------------+----------------------------+
| 10:20:10      | %H:%i:%s      | 0000-00-00 00:00:00.000000 |
| 10:20:10      | %h:%i:%s.%f   | 0000-00-00 00:00:00.000000 |
| 10:20:10      | %T            | 0000-00-00 00:00:00.000000 |
| 10:20:10AM    | %h:%i:%s%p    | 0000-00-00 00:00:00.000000 |
| 10:20:10AM    | %r            | 0000-00-00 00:00:00.000000 |
| 10:20:10.44AM | %h:%i:%s.%f%p | 0000-00-00 00:00:00.000000 |
+---------------+---------------+----------------------------+
6 rows in set (0.00 sec)

Expected behavior

mysql> SELECT date, format, STR_TO_DATE(date, format) as str_to_date FROM t1;
+---------------+---------------+----------------------------+
| date          | format        | str_to_date                |
+---------------+---------------+----------------------------+
| 10:20:10      | %H:%i:%s      | 0000-00-00 10:20:10.000000 |
| 10:20:10      | %h:%i:%s.%f   | 0000-00-00 10:20:10.000000 |
| 10:20:10      | %T            | 0000-00-00 10:20:10.000000 |
| 10:20:10AM    | %h:%i:%s%p    | 0000-00-00 10:20:10.000000 |
| 10:20:10AM    | %r            | 0000-00-00 10:20:10.000000 |
| 10:20:10.44AM | %h:%i:%s.%f%p | 0000-00-00 10:20:10.440000 |
+---------------+---------------+----------------------------+
6 rows in set (0.00 sec)

How To Reproduce

CREATE TABLE t1 (date CHAR(30), format CHAR(30));
INSERT INTO t1 VALUES
('10:20:10', '%H:%i:%s'),
('10:20:10', '%h:%i:%s.%f'),
('10:20:10', '%T'),
('10:20:10AM', '%h:%i:%s%p'),
('10:20:10AM', '%r'),
('10:20:10.44AM', '%h:%i:%s.%f%p');

SELECT date, format, STR_TO_DATE(date, format) as str_to_date FROM t1;

Environment

root@localhost:/# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB for Linux on x86_64 (build-)
build information as follow:
        Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
        Branch name: stonedb-5.7-dev
        Last commit ID: d0c2e01b6
        Last commit time: Date:   Wed Nov 2 19:58:00 2022 +0800
        Build time: Date: Sun 06 Nov 2022 08:50:06 AM UTC
root@ub01:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"

Are you interested in submitting a PR to solve the problem?

  • Yes, I will!

Metadata

Metadata

Assignees

Labels

A-bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions