I want to search dates in Mysql

Asked

Viewed 13 times

0

I need to search details of a table creating a precedent and using month and year as variables, but I do not know how I could do it, the column dataPedido is defined as Datetimethought about something like this, but I have no idea what to put after "LIKE".

DELIMITER $$
CREATE PROCEDURE buscaPedido(IN y int, m int)
    BEGIN
        DECLARE Y, M INT;
        SET @Y =y ,@M = m;
        SELECT * FROM pedido 
        WHERE dataPedido LIKE ... ;
    END;
$$
  • If your field is of type DATETIME then you should not use LIKE to compare. If you only want month and year then use the EXTRACT function to get the month and year and compare using the equal operator.

  • Got it here, now I need to search a date range using month and day

  • Then I think you should study about the operator BETWEEN. https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_between

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.