1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

Add $database->getTime() method for getting current ISO-8601 or unix timestamp from database

This commit is contained in:
Ryan Cramer
2021-07-28 10:37:52 -04:00
parent d815333eaf
commit 9e318c9688

View File

@@ -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;
}
}