How to do query in Pdo by date using input month?

0

I'dliketoknowhowIcanmakeanappointmentforthemonthyou'vechosenalongwiththename.TypeifIchooseAugustitwillonlycomeAugustmonthandsoon.

Thisisthequery

publicfunctionRetornaAtualizacoesFuncionarios($data,$codusuario){$WHERE=array();if(empty($codusuario)){$WHERE[]="codusuario = :codusuario";}else{ $WHERE[] = "codusuario != '37'"; }
        ;
        if( empty( $data   ) ) $WHERE[] = "DATE_FORMAT(data,'%Y-%m') = :data";          
    try {
         $Query = "SELECT 
        DISTINCT(usuario),
                date_format(data,'%d/%m/%Y %H:%i:%s') as data,
                codigo,
                nome 
                    FROM funcionarios
                         WHERE codusuario = '$codusuario'
                             ORDER BY data DESC  ";
        if( !empty($WHERE) ) $this->$Query .= ' WHERE '.implode(' AND ', $WHERE );

echo "<pre>"; print_r($_POST); 
echo "<pre>"; print_r($Query);exit;
        include_once $_SESSION['pmodel'].'/classes/mysqlconnection_class.php';
               $p_sql = MysqlConnection::getInstance()->prepare($Query);

                $_retorno = array(); 

                if($p_sql->execute()) {
                    while ($_result = $p_sql->fetch(PDO::FETCH_ASSOC))  {
                        $_retorno[] = $_result; 
                    }
                }

                return $_retorno;
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
        }
}

this is the input

<form class="form"  id="exibefuncionarios" method="post" target='_blank' action="gerar">
        <fieldset>
            <div style="border-radius:5px;padding:10px;">
                <table class="tbl_relatorio" cellspacing='0' width='100%' border ='0'>
                    <tr>
                        <td class='label_1'>Período:</td> 
                        <td>
                             <input style="width: 290px;" name='data' type='month'/>
                            </select>
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>
    
asked by anonymous 04.10.2016 / 14:48

1 answer

0

In order to filter certain records within MySQL, you can do the following:

Filtering records by Day

SELECT * FROM tabela WHERE DAY(data) = 'dia_escolhido'

Filtering records by month

SELECT * FROM tabela WHERE MONTH(data) = 'mes_escolhido'

Filtering records by Year

SELECT * FROM tabela WHERE YEAR(data) = 'ano_escolhido'

Using Day, Month, Year - can filter the data correctly.

    
25.10.2016 / 14:09