Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Empty date 1899
Wed, Nov 26 2008 3:23 AMPermanent Link

"Carlos"
DBISAM Ver. 3.30

Hello to all
Sometimes I have to copy a DateTime from a table to another.
For this use the following statement:

DB1.FieldByName ( 'MYDATE'). AsDateTime: = DB2.FieldByName ( 'MYDATE'_1').
AsDateTime;

Everything is fine, but if by chance the date of  DB2 is empty, the
DB1.'MYDATE' date field is saved as 1899  !!!

Whenever I am forced to do the following

if not DB2.FieldByName ( 'MYDATE'). IsNull then begin ... end;

It can avoid whenever do this "if"?

Thank you

Carlos

Wed, Nov 26 2008 4:54 AMPermanent Link

Mauricio Campana Nonino
Carlos,

Try:

DB1.FieldByName ( 'MYDATE'). Value: = DB2.FieldByName ( 'MYDATE'_1').
Value;


Mauricio Campana Nonino
Nonino Software
Wed, Nov 26 2008 3:26 PMPermanent Link

Sean
Carlos,

In addition to copying by TField.Value (a Variant), you can also use:

DB1.FieldByName ( 'MYDATE').Assign(DB2.FieldByName ( 'MYDATE'_1'))

As you've probably realized by now, copying by using
TField.AsInteger/Date/etc casts the field value to the requested type
(Integer, Date, etc) and so Null values get translated. Numerics go to
zero, strings go to empty, booleans to False. Date is really a floating
point , so you get Dec 31, 1899 which is the value represented by 0.

Hope this helped,

Sean

Carlos wrote:
> DBISAM Ver. 3.30
>
> Hello to all
> Sometimes I have to copy a DateTime from a table to another.
> For this use the following statement:
>
> DB1.FieldByName ( 'MYDATE'). AsDateTime: = DB2.FieldByName ( 'MYDATE'_1').
> AsDateTime;
>
> Everything is fine, but if by chance the date of  DB2 is empty, the
> DB1.'MYDATE' date field is saved as 1899  !!!
>
> Whenever I am forced to do the following
>
> if not DB2.FieldByName ( 'MYDATE'). IsNull then begin ... end;
>
> It can avoid whenever do this "if"?
>
> Thank you
>
> Carlos
>
>
Thu, Nov 27 2008 3:49 AMPermanent Link

"Carlos"
thanks!

Carlos

Image