Pankaj Gupta
Pankaj Gupta

Reputation: 146

How to get the exact date and time when mysql database table last updated?

Hi everyone I am new in web development and I am suffering from a problem to get date and time when mysql database table last updated because I have to show it on my web page. I am getting the last updated date correctly but not correct time please help me.

 <?php

    $sql = "SHOW TABLE STATUS FROM MydatabaseName LIKE 'TableName'";
    $tableStatus = mysql_query($sql);

while ($array = mysql_fetch_array($tableStatus)) {
          $updatetime = $array['Update_time'];

          $datetime = new DateTime($updatetime);
          echo $updatetime ;
     }

 ?>

Upvotes: 5

Views: 4370

Answers (3)

Spade
Spade

Reputation: 2280

If you have a relatively recent version of MySQL, you can query information_schema.tables

 select substr(update_time,1,10) as date_updated,
        substr(update_time,12) as time_updated 
 from information_schema.tables
 where 
 table_schema = 'name_of_your_database' and 
 table_name = 'your_table_name';

Note that this may not work for user-defined tables if your MySQL engine is InnoDB. It works as advertised on a MyISAM installation.

Upvotes: 0

Ashish
Ashish

Reputation: 643

If this could help you

SELECT UPDATE_TIME
FROM   information_schema.tables
WHERE  TABLE_SCHEMA = 'dbname'
AND TABLE_NAME = 'tabname'

How can I tell when a MySQL table was last updated?

Upvotes: 1

Priyanshu
Priyanshu

Reputation: 881

since you have tagged a question in mysql.

Did you try this? see if this is helpful.

select columns from table order by date_time column desc limit 1:

Upvotes: 0

Related Questions