From 9e318c9688acae0431adb1c3ad3f8ca8925b6eec Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 28 Jul 2021 10:37:52 -0400 Subject: [PATCH] Add $database->getTime() method for getting current ISO-8601 or unix timestamp from database --- wire/core/WireDatabasePDO.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wire/core/WireDatabasePDO.php b/wire/core/WireDatabasePDO.php index 01795ce2..c400d759 100644 --- a/wire/core/WireDatabasePDO.php +++ b/wire/core/WireDatabasePDO.php @@ -1711,5 +1711,19 @@ class WireDatabasePDO extends Wire implements WireDatabase { return $result; } + /** + * Get current date/time ISO-8601 string or UNIX timestamp according to database + * + * @param bool $getTimestamp Get unix timestamp rather than ISO-8601 string? (default=false) + * @return string|int + * @since 3.0.183 + * + */ + public function getTime($getTimestamp = false) { + $query = $this->query('SELECT ' . ($getTimestamp ? 'UNIX_TIMESTAMP()' : 'NOW()')); + $value = $query->fetchColumn(); + return $getTimestamp ? (int) $value : $value; + } + }