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:45 +00:00
parent b034fa0139
commit e3f9da7613

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)
*