There is a string '10/01/2016 00:00' which needs to be cast to mysql type DATETIME.

Trying to do this:

 select STR_TO_DATE('10/01/2016 00:00', '%d/%m/%Y %h:%i'); 

the format seems to be correct, and returns all the same NULL. What am I doing wrong?

    2 answers 2

    according to the documentation , the %h qualifier matches (I quote):

    Hour (01..12)

    you have the same hour as line 00 . accordingly, an attempt to convert it to a clock leads to an error.

    You probably have the clock in 24-hour format, and you need to use the %H specifier:

    Hour (00..23)

    i.e., the command should look like this:

     select str_to_date('10/01/2016 00:00', '%d/%m/%Y %H:%i'); 

      You use the mask %h - this is a clock in American format, the allowed values ​​are from 1 to 12 inclusive. 0 hours is not allowed, because it's 12:00 AM.

      Use the %H mask for time in 24 hour, i.e. from 00 to 23 format.