Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Mysql STR_TO_DATE give inconsistent result across different environment

I am running into an inconsistent behaviour across two different Docker image with the STR_TO_DATE function. On running on a ubuntu box and the other one running on my Mac.

On Linux:

SELECT STR_TO_DATE('203005','%H%i%s');
+--------------------------------+
| STR_TO_DATE('203005','%H%i%s') |
+--------------------------------+
| 20:30:05                       |
+--------------------------------+

SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.19    |
+-----------+

On my Mac:

SELECT STR_TO_DATE('203005','%H%i%s');
+--------------------------------+
| STR_TO_DATE('203005','%H%i%s') |
+--------------------------------+
| NULL                           |
+--------------------------------+

SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.12    |
+-----------+

show warnings; 
+---------+------+-------------------------------------------------------------+
| Level   | Code | Message                                                     |
+---------+------+-------------------------------------------------------------+
| Warning | 1411 | Incorrect datetime value: '203005' for function str_to_date |
+---------+------+-------------------------------------------------------------+

Both running Mysql on a Docker image:

      docker_container:
        name: mysql
        image: mysql:8.0
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

STR_TO_DATE will return NULL if you have an incomplete datetime value (in your case, there's no date) and SQL MODE NO_ZERO_DATE is set (see the manual). For example:

SET @@sql_mode = ''
;
SELECT @@sql_mode, STR_TO_DATE('203005','%H%i%s') AS date
;
SET @@sql_mode = 'NO_ZERO_IN_DATE'
;
SELECT @@sql_mode, STR_TO_DATE('203005','%H%i%s') AS date
;
SET @@sql_mode = 'NO_ZERO_DATE'
;
SELECT @@sql_mode, STR_TO_DATE('203005','%H%i%s') AS date

Output:

@@sql_mode          date
                    20:30:05
NO_ZERO_IN_DATE     20:30:05
NO_ZERO_DATE        null

Demo on dbfiddle

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!