You have to work with timestamp.
I save the dates in the database using:
date('Y-m-d H:i:s')
What is the default for mysql timestamp / datatime.
Now that you have a saved pattern, when reading this you convert the date (which comes as a string) to the date format with
strtotime
getting:
strtotime($suadatadobanco);
Then you will again use the date () function to get the fields of the date you want, if you just want the day to use 'd', for example:
date('d', strtotime($suadatadobanco))
Return will be the day of the month on that date.
For more information on the date function go to: link
Now you know how to get dates and their elements, now it's time to calculate the date difference.
To do this you transpose the dates into timestamp and then do the operations, remembering that the timestamp converts the complete date in seconds, that is, you add, subtract, divide and multiply the dates using seconds, after doing so you get the result and convert back to date.
Example:
You want to fit the difference of the data_1 in relation to the data_2, then you will do so:
$diferenca_em_timestamp = strtotime($suadatadobanco_data_1) - strtotime($suadatadobanco_data_2);
$difenca_em_dia = date('d', strtotime($diferenca_em_timestamp));
You can create a script of type "if the date is more than 7 days, display 'more than a week'" or "if it is less than 60 minutes display 'a few minutes'" ... this goes from your log and what you need ...
But there are javascript plugins that get the date you give and do this "conversion" for days / min / months ...
See the plugin:
link