Skip to content

Instantly share code, notes, and snippets.

@scr4bble
Last active March 5, 2026 11:44
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);
}
}
@hairpinNAT
Copy link

Hi, im trying to find out why this php script doesnt work in Adminer anymore..

@mtness
Copy link

mtness commented Feb 8, 2023

Hi, im trying to find out why this php script doesnt work in Adminer anymore..

I can confirm this, doesn't work in 4.8.1 anymore.
However, the javascript itself still works when pasted in the console, so i suspect this is only an issue with the way plugins are loaded now.

@scr4bble
Copy link
Author

scr4bble commented Feb 12, 2023

Hello, did it stop working for you after upgrading Adminer from 4.8.0 to 4.8.1?
I just upgraded to 4.8.1 and it works fine for me.
What PHP version do you use?
You can maybe also paste your adminer.php file here (censored if you have any keys inside, of course).
You can also try to disable other plugins to find out if some other plugin doesn't break this one.

@hairpinNAT
Copy link

I did not use Adminer several months, but now its working fine. I am on version 4.8.1

@vrana
Copy link

vrana commented Mar 16, 2025

Adminer 5 wrapped itself into a namespace and plugins now need to call Adminer's functions via this namespace.

Please update this Gist to this: https://gist.github.com/vrana/cf3869fb7cf567ec1f085d0965f5ade4

@tripulsTPfeffer
Copy link

To make this work in adminer 5 you need to set "class AdminerReadableDates extends Adminer\Plugin". Additionally the whole code can be reduced to the head function. Instead of using <<<EOT it is necessary to echo a script tag containing this JS code. But it seems that the JS code itself is not working anymore. I will inspect this this weekend and try to create a patch for this ;-)

@scr4bble
Copy link
Author

scr4bble commented Mar 3, 2026

Thanks! I haven't had time to do this yet as I am still postponing the Adminer update. Let me know then and I can replace/update the content of this gist. Not sure if it's still referenced anywhere.
EDIT: seems like it is still referenced

@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.

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