questions

Query database for last modified date

Rate this post

I am trying to query my WordPress server to echo the date of the last modified post.
In this case the database name is local and I am checking the posts table.

My current code is close to what I need, it will display the date and time as Y-m-d H:i (2021-01-13 12:18)

<?php

global $wpdb;
$result = $wpdb->get_results("SHOW TABLE STATUS FROM local LIKE 'wp_posts';");
foreach ($result as $data) {
    $updatetime = $data->Update_time;
}

$date = substr($updatetime, 0, -3);
echo $date;

?>

How do remove the time and display the date as d.n.Y?

 

✔️Solution:

You can use strtotime for that….

$date = substr($updatetime, 0, -3); // assuming this produces 2021-01-13 12:18
echo date("d.m.Y", strtotime($date));
// 13.01.2021

Leave a Reply

Your email address will not be published.

Back to top button