new method to abstract MySQL function unix_timestamp (convert db timestamp to integer)

This commit is contained in:
Ralf Becker 2010-09-09 09:06:13 +00:00
parent f5f47c4ad1
commit 83dae424e0

View File

@ -1232,6 +1232,28 @@ class egw_db
return call_user_func_array(array(&$this->Link_ID,'concat'),$args);
}
/**
* Convert a DB specific timestamp in a unix timestamp stored as integer, like MySQL: UNIX_TIMESTAMP(ts)
*
* @param string $expr name of an integer column or integer expression
* @return string SQL expression of type timestamp
*/
function unix_timestamp($expr)
{
switch($this->Type)
{
case 'mysql':
return "UNIX_TIMESTAMP($expr)";
case 'pgsql':
return "DATE_PART('epoch',$expr)";
case 'mssql':
return "DATEDIFF(second,'1970-01-01',($expr))";
}
}
/**
* Convert a unix timestamp stored as integer in the db into a db timestamp, like MySQL: FROM_UNIXTIME(ts)
*