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:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user