- Load the date from the database using a
mysqli_query
and store the result in $original_date
.
- Create a date object from the string in the database.
$old_date = new DateTime($original_date);
- Get the current date in the same format and store it in another variable.
$current_date = new DateTime(date("m-d-Y H:m:s"));
- Get the difference between the two dates.
$difference = $old_date->diff($current_date);
- Convert the difference to minutes and display message.
echo($difference->m . "minutes ago");
Here is the full code for you to use:
# Get database value and store in $original_date
$old_date = new DateTime($original_date);
$current_date = new DateTime(date("m-d-Y H:m:s"));
$difference = $old_date->diff($current_date);
echo($difference->m . "minutes ago");