Skip to content

Instantly share code, notes, and snippets.

@scr4bble
Last active March 6, 2026 21:06
Show Gist options
  • Select an option

  • Save scr4bble/9ee4a9f1405ffc1465f59e03768e2768 to your computer and use it in GitHub Desktop.

Select an option

Save scr4bble/9ee4a9f1405ffc1465f59e03768e2768 to your computer and use it in GitHub Desktop.
Adminer plugin that replaces UNIX timestamps with human-readable dates.
<?php
/** This plugin replaces UNIX timestamps with human-readable dates in your local format.
* Mouse click on the date field reveals timestamp back.
*
* @link https://www.adminer.org/plugins/#use
* @author Anonymous
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerReadableDates extends Adminer\Plugin {
/** @access protected */
var $prepend;
function __construct() {
$this->prepend = <<<EOT
document.addEventListener('DOMContentLoaded', function(event) {
var date = new Date();
var tds = document.querySelectorAll('td[id^="val"]');
for (var i = 0; i < tds.length; i++) {
var text = tds[i].innerHTML.trim();
if (text.match(/^\d{10}$/)) {
date.setTime(parseInt(text) * 1000);
tds[i].oldDate = text;
// tds[i].newDate = date.toUTCString().substr(5); // UTC format
tds[i].newDate = date.toLocaleString(); // Local format
// tds[i].newDate = date.toLocaleFormat('%e %b %Y %H:%M:%S'); // Custom format - works in Firefox only
tds[i].newDate = '<span style="color: #009900">' + tds[i].newDate + '</span>';
tds[i].innerHTML = tds[i].newDate;
tds[i].dateIsNew = true;
tds[i].addEventListener('click', function(event) {
this.innerHTML = (this.dateIsNew ? this.oldDate : this.newDate);
this.dateIsNew = !this.dateIsNew;
});
}
}
});
EOT;
}
function head() {
echo Adminer\script($this->prepend);
}
}
@tripulsTPfeffer
Copy link

tripulsTPfeffer commented Mar 3, 2026

This one works fine.

<?php

/** This plugin replaces UNIX timestamps with human-readable dates in your local format.
* Mouse click on the date field reveals timestamp back.
*
* @link https://www.adminer.org/plugins/#use
* @author Anonymous
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerReadableDates extends Adminer\Plugin {
        /** @access protected */
        var $prepend;

        function __construct() {
                $this->prepend = <<<EOT
document.addEventListener('DOMContentLoaded', function(event) {
        var date = new Date();
        var tds = document.querySelectorAll('td[id^="val"]');
        for (var i = 0; i < tds.length; i++) {
                var text = tds[i].innerHTML.trim();
                if (text.match(/^\d{10}$/)) {
                        date.setTime(parseInt(text) * 1000);
                        tds[i].oldDate = text;
                        // tds[i].newDate = date.toUTCString().substr(5); // UTC format
                        tds[i].newDate = date.toLocaleString(); // Local format
                        // tds[i].newDate = date.toLocaleFormat('%e %b %Y %H:%M:%S'); // Custom format - works in Firefox only
                        tds[i].newDate = '<span style="color: #009900">' + tds[i].newDate + '</span>';
                        tds[i].innerHTML = tds[i].newDate;
                        tds[i].dateIsNew = true;
                        tds[i].addEventListener('click', function(event) {
                                this.innerHTML = (this.dateIsNew ? this.oldDate : this.newDate);
                                this.dateIsNew = !this.dateIsNew;
                        });
                }
        }
});
EOT;
        }

        function head() {
                echo Adminer\script($this->prepend);
        }
}

@scr4bble
Copy link
Author

scr4bble commented Mar 5, 2026

I have updated these two lines:

class AdminerReadableDates extends Adminer\Plugin {
...
		echo Adminer\script($this->prepend);

Let me know please if there are any issues with the latest version.

@ram4nd
Copy link

ram4nd commented Mar 6, 2026

A lot better way to do this:

public function selectVal(&$val, $link, $field, $original)
  {
    if (!is_numeric($val)) {
      return null;
    }

    $ts = (int) $val;

    // detect milliseconds
    if ($ts > 1000000000000) {
      $ts = (int) ($ts / 1000);
    }

    // basic unix timestamp range
    if ($ts > 1000000000 && $ts < 20000000000) {
      $val = gmdate('Y-m-d H:i:s', $ts);
    }

    return null;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment