Filter schedule by date

0

I need to filter a schedule by dates, in this courses will be registered throughout the year but I need to show only those of the month

$fecha_filtro = date('Y/m/d');

if ($fecha_filtro == '05'){
$pg = "select * from cronograma where fecha ilike '%".$fecha_filtro."%'";
$query = pg_query($pg);
}

The 05 of the if is the month that I need to filter, as I have it does not work.

    
asked by Edwin Aquino 02.05.2017 в 20:06
source

1 answer

0
  

If the field fecha is of the type date and the format of the date is the default one ( Y-m-d )

To filter only those of the month in curso ( that is, current month ), you can do the following:

$fechaDesde = date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y')));
$fechaHasta = date('Y-m-d', mktime(0, 0, 0, date('m') + 1, 1, date('Y')));

$pg = "select * from cronograma 
       where fecha >= '".$fechaDesde."'::DATE 
       and fecha < '".$fechaHasta."'::DATE";
$query = pg_query($pg);
    
answered by 02.05.2017 / 20:53
source