compare the date of one row with the date of another

-1

Greetings to all, I annoy you with a concern that I have.

Currently I am in a project, I am new in this of the programming. It's a page, I make a query to a mysql database and I show it using a WHILE.

Always the query shows a table with 6 columns that contain the id, a date, names, emails, etc.

What I need to know is if there is a way to compare the date of one row with the date of another, since the records are usually from different months and I need to show, in case it applies, how many months are between one and another.

Beforehand, thank you all for your answers.

Greetings !!

    
asked by José Miguel Viña 01.12.2017 в 22:55
source

1 answer

0

Here I leave the code of the query. As it shows there, from the database I bring a field called date, those dates vary. I need to know if between a register (row) of those that the While shows, if there are months in which no data was recorded. Example: I have records 3 records with dates (2017-09-12) (2017-11-12) (2017-12-12). I want to know if there is any way to get that time lapse between the record that has a September date and the one that has a November date.

$ sql="SELECT * FROM invoices WHERE id = $ 'id'";

                        $query=mysqli_query($con,$sql);


                        $contar=mysqli_num_rows($query);



                        if($contar>0){


                            echo"<table>

                                <tr>
                                    <td>Nombre</td>
                                    <td>fecha</td>
                                    <td>pago</td>
                                </tr>";


                            while ($fila=mysqli_fetch_array($query)) {


                                echo"
                                <tr>
                                    <td>$filaMT['nombre']</td>
                                    <td>$filaMT['fecha']</td>
                                    <td>$filaMT['pago']</td>
                                </tr>";
                            }

                            echo"</table>";
    
answered by 04.12.2017 в 18:23