Subject Re: [firebird-support] Re: Problem with TIMESTAMP field precision
Author Ivan Prenosil
> begin
> timestamp_date := Trunc(Value)-IBDateOffset;
> timestamp_time := Round(IBTimeDivider*Abs(Frac(Value)));
> end;

It is still not 100% correct.
If you have time very close to midnight, it could be Rounded to next day,
i.e. something like
23:59:59.9999 -> 1 day + 0:0:0
Because date and time are stored separately,
and because the whole day will be cut off from time part
by Firebird, as a result you will loose one whole day !

Ivan
http://www.volny.cz/iprenosil/interbase/


----- Original Message -----
From: "alexanderl3" <alexanderl@...>
To: <firebird-support@yahoogroups.com>
Sent: Thursday, August 18, 2005 12:00 PM
Subject: [firebird-support] Re: Problem with TIMESTAMP field precision


> IBSQL.PAS
>
> This is in IBX5. Make sure you have the latest version. Commented
> out lines are those that were there before.
>
> const
> IBTimeDivider=24*60*60*10000;
> IBDateOffset=-15018;
>
> procedure TIBXSQLVAR.SetAsDateTime(Value: TDateTime);
> var
> i: Integer;
> tm_date: TCTimeStructure;
> Yr, Mn, Dy, Hr, Mt, S, Ms: Word;
> xvar: TIBXSQLVAR;
> begin
> if IsNullable then
> IsNull := False;
> for i := 0 to FParent.FCount - 1 do
> if FParent.FNames[i] = FName then
> begin
> xvar := FParent[i];
> xvar.FXSQLVAR^.sqltype := SQL_TIMESTAMP or
> (xvar.FXSQLVAR^.sqltype and 1);
> // DecodeDate(Value, Yr, Mn, Dy);
> // DecodeTime(Value, Hr, Mt, S, Ms);
> // with tm_date do begin
> // tm_sec := S;
> // tm_min := Mt;
> // tm_hour := Hr;
> // tm_mday := Dy;
> // tm_mon := Mn - 1;
> // tm_year := Yr - 1900;
> // end;
> // xvar.FXSQLVAR^.sqllen := SizeOf(TISC_QUAD);
> // IBAlloc(xvar.FXSQLVAR^.sqldata, 0,
> xvar.FXSQLVAR^.sqllen);
> // isc_encode_date(@tm_date, PISC_QUAD
> (xvar.FXSQLVAR^.sqldata));
> xvar.FXSQLVAR^.sqllen := SizeOf(TISC_TIMESTAMP);
> IBAlloc(xvar.FXSQLVAR^.sqldata, 0, xvar.FXSQLVAR^.sqllen);
> With PISC_TIMESTAMP(xvar.FXSQLVAR^.sqldata)^ do
> begin
> timestamp_date := Trunc(Value)-IBDateOffset;
> timestamp_time := Round(IBTimeDivider*Abs(Frac(Value)));
> end;
>
> xvar.FModified := True;
> end;
> end;
>
> --- In firebird-support@yahoogroups.com, "ibrahim bulut"
> <i.bulut@i...> wrote:
>> i have a question
>> which unit of IBX you changed with this code
>>
>>
>>
>> ----- Original Message -----
>> From: "alexanderl3" <alexanderl@o...>
>> To: <firebird-support@yahoogroups.com>
>> Sent: Thursday, August 18, 2005 2:33 AM
>> Subject: [firebird-support] Re: Problem with TIMESTAMP field
> precision
>>
>>
>> > Thanks a lot. It works fine now.
>> >
>> >
>> > --- In firebird-support@yahoogroups.com, "Dmitry Sibiryakov"
>> > <SD@t...> wrote:
>> >> On 17 Aug 2005 at 1:01, alexanderl3 wrote:
>> >>
>> >> >Is it a bug or I need to change some settings to allow higher
>> >> >resolution? Is it in IBX5, API DLL or FB itself?
>> >>
>> >> This is a bug. From my POV it is in IB API
> (isc_encode_timestamp
>> > ())
>> >> and IBX (that use this function).
>> >>
>> >> >If it is IBX5 problem, what other controls can be used to work
> with
>> >> >miliseconds?
>> >>
>> >> Hands.drv and Brain.sys.
>> >>
>> >> const
>> >> IBTimeDivider=24*60*60*10000;
>> >> IBDateOffset=-15018;
>> >>
>> >>
>> >> Field.AsDateTime := Date; // Initialize buffer
>> >> With PISC_TIMESTAMP(Field.Data^.sqldata)^ do
>> >> begin
>> >> timestamp_date := Trunc(Value)-IBDateOffset;
>> >> timestamp_time := Round(IBTimeDivider*Abs(Frac(Value)));
>> >> end;
>> >>
>> >> --
>> >> SY, Dimitry Sibiryakov.