[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Phpgroupware-developers] minor patch for mssql
From: |
Bradley Bell |
Subject: |
Re: [Phpgroupware-developers] minor patch for mssql |
Date: |
Fri, 14 Dec 2001 16:33:40 -0800 |
User-agent: |
Mutt/1.2.5i |
On Fri, Dec 14, 2001 at 07:55:13AM -0600, Michael Dean wrote:
> This has been applied. BTW, the FreeTDS seems to format dates a bit
> differently than the native M$ and Sybase drivers. Those drivers spew
> out English dates with text and are not guaranteed parseable. So, if
> the seconds are being chopped off, I'd point the finger at FreeTDS.
There is another way to do it, I ran across this this technique in mrbs
(http://mrbs.sourceforge.net/) instead of having a function for each
platform that converts from one format to another, it has a function that
generates SQL code specific to the database, that will return a unix
timestamp.
so, for mssql and sybase, you have a function like this:
function sql_syntax_timestamp_to_unix($fieldname)
{
return " DATEDIFF(ss, '1970-01-01 00:00:00.000', $fieldname) ";
}
Thse two are taken straight from mrbs:
mysql:
function sql_syntax_timestamp_to_unix($fieldname)
{
return " UNIX_TIMESTAMP($fieldname) ";
}
pgsql:
function sql_syntax_timestamp_to_unix($fieldname)
{
return " DATE_PART('epoch', $fieldname) ";
}
and one would use it like so:
$this->db->query("select $this->db->sql_syntax_timestamp_to_unix("date") from
foo");
-brad
--
Bradley Bell
Computer Support Analyst
University of Washington
Classroom Support Services