Subtract or add month to a [duplicate] date

0

I am working with Highcharts and I am showing information from my database in the following way:

      data: [<?php  
        if ($result->num_rows > 0) {
          while($row = $result->fetch_assoc()) {
        echo "[Date.UTC(".date('y,m,d', strtotime($row['fecha_emision']))."),".$row['total_dia']."],"; 

        }
        } 
    ?>

But the problem is that my script considers the first month as 0. So when my database shows the following date:

[Date.UTC (2016, 06, 6), 14]

Consider this date as July 6 when in fact it should be June 6 .

The solution is as follows:

    data: [<?php  
    if ($result->num_rows > 0) {
      while($row = $result->fetch_assoc()) {
        //RESTAMOS UN MES LA FECHA, PUES JAVASCRIPT CONSIDERA EL PRIMER MES 0;
       $fecha_emision=$row['fecha_emision'];
    echo "[Date.UTC(".date('y,m,d', strtotime("-1 month", strtotime($fecha_emision)))."),".$row['total_dia']."],"; 

    }
    } 
?>

    ]
    
asked by Raphael 07.07.2016 в 18:43
source

1 answer

3

would be something more or less like this

  $actual = strtotime($row['fecha_emision']);
  $mesmenos = date("Y,m,d", strtotime("-1 month", $actual));

this subtracts 1 month from the date you are currently assigning, if you need to add 1 month plus +1 month

    
answered by 07.07.2016 / 18:51
source