Skip to Content.
Sympa Menu

freetds - Re: [freetds] FreeTDS returned data lenght????

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Ole Hansen <oha AT city.dk>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] FreeTDS returned data lenght????
  • Date: Thu, 16 Oct 2003 02:31:35 +0200

On Thu, 2003-10-16 at 01:33, Craig Davison wrote:
> On Thu, Oct 16, 2003 at 12:34:10AM +0200, Ole Hansen wrote:
> > Sorry for the interruption :)
> > I an application I do the following when calculating the time as I want
> > the time to be represented as UNIX-time used in my application:
> >
> > DATETIME:
> > -------------
> > double time;
> > u_int32_t days = *((u_int32_t *)value);
> > u_int32_t msec = *((u_int32_t *)(value+sizeof(u_int32_t)));
> > time = ((double)(days-25567))*24*60*60 + ((double)msec)/1000.0;
> >
> > The day calculated gives me the expected day but the usec doesnt match.
> > This is for CS_DATETIME_TYPE. The calculated value is 8-10 hours behind.
>
> Sort of off-topic, but why not solve this with a query using datediff. An
> example using getdate():
>
> SELECT DATEDIFF (SECOND, '1970-01-01', GETDATE()),
> DATEPART (MILLISECOND, GETDATE())
>
> Will return the UNIX date (seconds since the epoch) and millisecond part
> without mucking around with arithmetic in your code...

In my application I do not know the query used. I only get the values
returned by ct_fetch and the type of it and I do the conversion to
string/float or whatever needed/requested. However, the upper layer
cannot change the query method as this must be kind of generic and
suitable with other DB's as well. I.e. my driver could be replaced with
something else. Thats why I do the math.







Archive powered by MHonArc 2.6.24.

Top of Page