diff --git a/doc/Developing/Style-Guidelines.md b/doc/Developing/Style-Guidelines.md
index cef63a7ee8..d6acb1265f 100644
--- a/doc/Developing/Style-Guidelines.md
+++ b/doc/Developing/Style-Guidelines.md
@@ -37,4 +37,26 @@ do this but provides so much flexibility along with stopping the need for retrie
place.
As an example pull request, see [PR 706](https://github.com/librenms/librenms/pull/706/files) to get an idea of what
-it's like to convert an existing pure html table to Bootgrid.
\ No newline at end of file
+it's like to convert an existing pure html table to Bootgrid.
+
+### Datetime format
+
+When displaying datetimes, please ensure you use the format YYYY-MM-DD mm:hh:ss where possible, you shouldn't change the
+order of this as it will be confusing to users. Cutting it short to just display YYYY-MM-DD mm:hh is fine :).
+
+To keep things consistent we have the following variables which should be used rather than to format dates yourself.
+This has the added benefit that users can customise the format:
+
+```php
+# Date format for PHP date()s
+$config['dateformat']['long'] = "r"; # RFC2822 style
+$config['dateformat']['compact'] = "Y-m-d H:i:s";
+$config['dateformat']['byminute'] = "Y-m-d H:i";
+$config['dateformat']['time'] = "H:i:s";
+
+# Date format for MySQL DATE_FORMAT
+$config['dateformat']['mysql']['compact'] = "%Y-%m-%d %H:%i:%s";
+$config['dateformat']['mysql']['date'] = "%Y-%m-%d";
+$config['dateformat']['mysql']['time'] = "%H:%i:%s";
+```
+
diff --git a/html/includes/modal/alert_schedule.inc.php b/html/includes/modal/alert_schedule.inc.php
index 6afb748fb7..7c6b7b628e 100644
--- a/html/includes/modal/alert_schedule.inc.php
+++ b/html/includes/modal/alert_schedule.inc.php
@@ -48,13 +48,13 @@ if(is_admin() !== false) {
@@ -208,7 +208,7 @@ $('#map-stub').typeahead({
$(function () {
$("#start").datetimepicker({
- minDate: ''
+ minDate: ''
});
$("#end").datetimepicker();
$("#start").on("dp.change", function (e) {
diff --git a/html/includes/reports/alert-log.pdf.inc.php b/html/includes/reports/alert-log.pdf.inc.php
index b44023620b..5ee0e91ea1 100644
--- a/html/includes/reports/alert-log.pdf.inc.php
+++ b/html/includes/reports/alert-log.pdf.inc.php
@@ -32,7 +32,7 @@ $pdf->AddPage('L');
$numresults = 250;
}
- $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate $query LIMIT $start,$numresults";
+ $full_query = "SELECT D.device_id,name,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate $query LIMIT $start,$numresults";
foreach (dbFetchRows($full_query, $param) as $alert_entry) {
$hostname = gethostbyid(mres($alert_entry['device_id']));
diff --git a/html/includes/table/alert-schedule.inc.php b/html/includes/table/alert-schedule.inc.php
index ba6f9884cc..635e67be92 100644
--- a/html/includes/table/alert-schedule.inc.php
+++ b/html/includes/table/alert-schedule.inc.php
@@ -46,7 +46,7 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
-$sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '%D %b %Y %T') AS `start`, DATE_FORMAT(`S`.`end`, '%D %b %Y %T') AS `end`, `S`.`title` $sql";
+$sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '".$config['dateformat']['mysql']['compact']."') AS `start`, DATE_FORMAT(`S`.`end`, '".$config['dateformat']['mysql']['compact']."') AS `end`, `S`.`title` $sql";
foreach (dbFetchRows($sql,$param) as $schedule) {
$status = 0;
diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php
index 860d6066fe..0c8e515e62 100644
--- a/html/includes/table/alertlog.inc.php
+++ b/html/includes/table/alertlog.inc.php
@@ -39,7 +39,7 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
-$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '%D %b %Y %T') as humandate,details $sql";
+$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql";
$rulei = 0;
foreach (dbFetchRows($sql,$param) as $alertlog) {
diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php
index c2bd64e4f1..d5e5e7d60e 100644
--- a/html/includes/table/eventlog.inc.php
+++ b/html/includes/table/eventlog.inc.php
@@ -46,7 +46,7 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
-$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate $sql";
+$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate $sql";
foreach (dbFetchRows($sql,$param) as $eventlog) {
$dev = device_by_id_cache($eventlog['host']);
diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php
index ca041fe2ad..81df05d289 100644
--- a/html/includes/table/syslog.inc.php
+++ b/html/includes/table/syslog.inc.php
@@ -60,7 +60,7 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
-$sql = "SELECT S.*, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date $sql";
+$sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql";
foreach (dbFetchRows($sql,$param) as $syslog) {
$dev = device_by_id_cache($syslog['device_id']);
diff --git a/html/pages/authlog.inc.php b/html/pages/authlog.inc.php
index 606345526e..64b4080ad2 100644
--- a/html/pages/authlog.inc.php
+++ b/html/pages/authlog.inc.php
@@ -4,7 +4,7 @@ if ($_SESSION['userlevel'] >= '10')
{
echo("
");
- foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry)
+ foreach (dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `authlog` ORDER BY `datetime` DESC LIMIT 0,250") as $entry)
{
if ($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; }
diff --git a/html/pages/bill.inc.php b/html/pages/bill.inc.php
index c6c0029e65..13b640057b 100644
--- a/html/pages/bill.inc.php
+++ b/html/pages/bill.inc.php
@@ -50,8 +50,8 @@ if (bill_permitted($bill_id))
$bill_color = "#0000cc";
}
- $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '%M %D %Y')");
- $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '%M %D %Y')");
+ $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')");
+ $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')");
$unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
$unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
diff --git a/html/pages/bill/transfer.inc.php b/html/pages/bill/transfer.inc.php
index fd317393d2..194db3446e 100644
--- a/html/pages/bill/transfer.inc.php
+++ b/html/pages/bill/transfer.inc.php
@@ -25,8 +25,8 @@
$in_data = $bill_data['total_data_in'];
$out_data = $bill_data['total_data_out'];
- $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '%M %D %Y')");
- $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '%M %D %Y')");
+ $fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')");
+ $totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')");
$unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
$unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
$unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')");
diff --git a/html/pages/device/logs/eventlog.inc.php b/html/pages/device/logs/eventlog.inc.php
index 57753f048c..aec8bdd98c 100644
--- a/html/pages/device/logs/eventlog.inc.php
+++ b/html/pages/device/logs/eventlog.inc.php
@@ -31,7 +31,7 @@ if( !empty($_POST['string']) ) {
$sql .= " AND message LIKE '%".mres($_POST['string'])."%'";
}
-$entries = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate FROM `eventlog` WHERE `host` = ? $sql ORDER BY `datetime` DESC LIMIT 0,250", array($device['device_id']));
+$entries = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? $sql ORDER BY `datetime` DESC LIMIT 0,250", array($device['device_id']));
echo('
diff --git a/html/pages/device/logs/syslog.inc.php b/html/pages/device/logs/syslog.inc.php
index 6ff642123d..7aae3b8e0c 100644
--- a/html/pages/device/logs/syslog.inc.php
+++ b/html/pages/device/logs/syslog.inc.php
@@ -40,7 +40,7 @@ if ($_POST['program'])
$param[] = $_POST['program'];
}
-$sql = "SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog WHERE device_id = ? $where";
+$sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? $where";
$sql .= " ORDER BY timestamp DESC LIMIT 1000";
echo('
diff --git a/html/pages/device/overview/eventlog.inc.php b/html/pages/device/overview/eventlog.inc.php
index 1fb306c679..ff235aa4a8 100644
--- a/html/pages/device/overview/eventlog.inc.php
+++ b/html/pages/device/overview/eventlog.inc.php
@@ -10,7 +10,7 @@ echo("

Recent Events");
echo('
');
-$eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '%d/%b/%y %T') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id']));
+$eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate FROM `eventlog` WHERE `host` = ? ORDER BY `datetime` DESC LIMIT 0,10", array($device['device_id']));
foreach ($eventlog as $entry)
{
include("includes/print-event-short.inc.php");
diff --git a/html/pages/device/overview/syslog.inc.php b/html/pages/device/overview/syslog.inc.php
index b473078a55..1d26fbb2a7 100644
--- a/html/pages/device/overview/syslog.inc.php
+++ b/html/pages/device/overview/syslog.inc.php
@@ -2,7 +2,7 @@
if ($config['enable_syslog'])
{
- $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '%Y-%m-%d %T') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id']));
+ $syslog = dbFetchRows("SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog WHERE device_id = ? ORDER BY timestamp DESC LIMIT 20", array($device['device_id']));
if (count($syslog))
{
echo('');
diff --git a/html/pages/device/port/events.inc.php b/html/pages/device/port/events.inc.php
index 3cdd09c7b3..6de49ef262 100644
--- a/html/pages/device/port/events.inc.php
+++ b/html/pages/device/port/events.inc.php
@@ -1,6 +1,6 @@
');
foreach ($entries as $entry)
diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php
index 5ce3e608cc..ca96e6559c 100644
--- a/html/pages/device/showconfig.inc.php
+++ b/html/pages/device/showconfig.inc.php
@@ -48,7 +48,7 @@ if ($_SESSION['userlevel'] >= "7")
if ($vars['rev'] == $svnlog["rev"]) {
echo('