How to use the LIKE with a DATE_FORMAT?

2

I have a query where I need to do a LIKE in WHERE indicating the current date.

It's this:

SELECT orden FROM tareas WHERE tipo = "Dos" 
AND (fechaCierre IS NULL OR fechaCierre LIKE DATE_FORMAT(NOW(), '%Y-%m-%d'))

Of course, that of DATE_FORMAT(NOW(), '%Y-%m-%d') returns "2018-10-19", but I want the WHERE to behave like LIKE '2018-10-19%' , but I do not know how to put the% LIKE of the query.

I do not know if I explain. I want to put the% in the LIKE after the "operation" of DATE_FORMAT, but it does not work for me.

I've tried to put LIKE (DATE_FORMAT(NOW(), '%Y-%m-%d'))% LIKE [DATE_FORMAT(NOW(), '%Y-%m-%d')]% LIKE DATE_FORMAT(NOW(), '%Y-%m-%d') + % and nothing, there's no way it works.

Greetings.

    
asked by M. Giner 19.10.2018 в 11:00
source

1 answer

2

To concatenate fields or strings in MySQL :

1.- Using the function CONCAT(campo1, campo2, ...) . The returned value is the concatenated string of all the parameters.

LIKE CONCAT(DATE_FORMAT(NOW(), '%Y-%m-%d'), '%')

2.- Using the operator || in the following way: campo1 || campo2 . For this to work it is necessary to set the variable sql_mode to the value PIPES_AS_CONCAT :

SET sql_mode=PIPES_AS_CONCAT;

...
LIKE DATE_FORMAT(NOW(), '%Y-%m-%d') || '%'
...
    
answered by 19.10.2018 / 11:19
source