[freetds] FreeTDS returned data lenght????

Craig Davison cd at securityfocus.com
Wed Oct 15 18:33:27 EDT 2003


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...

-- 
Craig Davison
Symantec Corporation
+1 (403) 261-5434


More information about the FreeTDS mailing list