Make field month filter date ("Y-m-d")

0

Hello I have this form I want to filter with only the month that when selecting a me

   
      
       <?php
          
           if(isset($_POST["mes"])&& $_POST["mes"]>0)
            $consulta.=" AND s.fecha=".$_POST['mes'];
           
           
           
     
$so ="SELECT s.Id_folio, s.fecha, d.id_departamento, d.nombre,s.descripcion_trabajo, s.observaciones, s.Id_servicio,s.tipo_solicitud, s.costo,  s.id_vehiculo, u.Empleado_Nombre, u.Empleado_id, t.Id_servicio, t.Nombre_servicio,s.Autoriza_Soli,s.Autoriza_Ger,s.Autoriza_GerIs,s.Autoriza_trab,s.Autoriza_termi FROM solicitud as s, departamento as d ,usuarios as u, tipo_servicio as t  WHERE s.id_departamento=d.id_departamento and s.Empleado_id =u.Empleado_id and s.Id_servicio =t.Id_servicio and  Autoriza_Soli=1 and Autoriza_Ger =2 and Autoriza_GerIs=3 and Autoriza_trab=4 and Autoriza_termi=5 ".$consulta."";
           
     
                   $mostrarso=mysql_query($so);
				  while($i=mysql_fetch_array($mostrarso)){
date_default_timezone_set('Europe/Madrid');//en esta parte divido mi campo fecha para que me muestre solo el mes con nombre
setlocale(LC_TIME, 'es_ES.UTF-8');
setlocale(LC_TIME, 'spanish');
$nombremes=strftime("%B", strtotime($fecha_mes=$i[1]));
$fecha_mes=$i[1];
$partes = explode('-', $fecha_mes);
$_fecha = "{$partes[2]}-{$partes[1]}-{$partes[0]} "

                ?>
           

but how can I do the month query?

    
asked by Esther 16.11.2018 в 18:33
source

1 answer

1

first get the month of the s.date with the MONTH function of mysql and compare it with the month that arrives for $ _POST ['month'] this must be numeric

example:

$consulta.=" AND MONTH(s.fecha)=".$_POST['mes'];

s.date must be defined as date on your table

    
answered by 16.11.2018 в 18:59