Skip to content
Advertisement

Query database for last modified date

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?

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement