Incorrect datetime value

0

I am trying to insert some data by php into my database, when making the INSERT I get the following error:

Error de MySQL : 1411 : Incorrect datetime value: '21/09/2018' for function 
str_to_date.

I leave the insertion code:

$SQL = "INSERT INTO control_gasolio.registros 
(nombre,proveedor_gasolio,tipo_gasolio,litros,euros,numero_tarjeta,fecha)
values 
('$nombre','$proveedor','$gasoleo','$litros','$euros','$tarjeta',STR_TO_DATE( 
'$fecha', '%d-%m-%Y' ))";

I would appreciate some help in knowing what my mistake may be. Thanks

    
asked by hayber 21.09.2018 в 16:22
source

1 answer

0

It is possible that the error is indirect and really comes from PHP itself, from the mysql console you can try this:

mysql> SET @@SESSION.sql_mode='ALLOW_INVALID_DATES';

This will ignore the error, however it is advisable to make a% SELECT to clarify if there has not been any strange behavior when performing INSERT .

Otherwise the data type DATE MySQL stores your date with the following format: YYYY-MM-DD, consider leaving it by default.

Anyway, if it still does not work, you could check that the String that you pass through PHP does not have tabs, spaces or directly copy and paste that you receive, for example doing a echo ? So we could get something more clear.

    
answered by 21.09.2018 в 16:56