From cbaf4b7536c0b056bc8079aa39b24f2e2c312dd6 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Jan 2020 20:00:37 +0000 Subject: introduce db_str_to_date() --- include/dba/dba_driver.php | 4 ++++ include/dba/dba_pdo.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index cfb208e2d..b96601fec 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -307,6 +307,10 @@ function db_use_index($str) { return \DBA::$dba->use_index($str); } +function db_str_to_date($str) { + return \DBA::$dba->str_to_date($str); +} + /** * @brief Execute a SQL query with printf style args. * diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php index 0279342ec..0ae69fe27 100755 --- a/include/dba/dba_pdo.php +++ b/include/dba/dba_pdo.php @@ -139,6 +139,15 @@ class dba_pdo extends dba_driver { } } + function str_to_date($str) { + if($this->driver_dbtype === 'pgsql') { + return "TO_TIMESTAMP($str, 'YYYY-MM-DD HH:MI:SS')"; + } + else { + return "STR_TO_DATE($str, '%Y-%m-%d %H:%i:%s')"; + } + } + function quote_interval($txt) { if($this->driver_dbtype === 'pgsql') { return "'$txt'"; -- cgit v1.2.3