#Dear I am having a problem in this query since an estimate helped me a little. But I have a problem because the foreign key no longer shows me the data that I need and I have that problem. I've been reading but haven't been able to get it to work right. #Dear how can I use DATEDIFF in that query. my old query was
:SELECT id_seguro_obligatorio,DATEDIFF(vencimiento_seg_oblig,CURDATE()) AS contador,patente_tracto,n_poliza,date_format(fecha_seg_oblig,'%d-%m-%Y') as fecha_seg_oblig , date_format(vencimiento_seg_oblig,'%d-%m-%Y') as vencimiento_seg_oblig,valor_seg_obligatorio,archivo_seg_oblig FROM seguro_obligatorio INNER JOIN tracto ON tracto.id_tracto=seguro_obligatorio.tracto_id_tracto
Without wishing to be unfriendly, how DATEDIFF works in MySQL is the first thing you would find if you googled it. However, the important thing is that the function accepts fields of type DATE or DATETIME, indistinctly. The answer always comes in days.
From the above, what you call
contador
:Represents the days that have passed since the mandatory insurance expired to the present. When the insurance is still valid it
contador
will be negative.Getting "the rows in light blue" is equivalent to having us look for the 7 differences. It would be less cryptic to express it as: "get the records whose compulsory insurance is expired". You would put this in the WHERE clause, for example