Board index » cppbuilder » TDateTime. How can I do...

TDateTime. How can I do...


2003-07-10 11:48:37 PM
cppbuilder71
I need to store in the field of the InterBase (TimeStamp) the date and the
time in the same field.
But, when I put the time in this field I lost the date value.
How can I store both value.
Did I believe that it was easier to manipulate the values, or am I making
something bad?
My code :
//--------------------------------------------------------------------------
-
TDateTime TDM::SetHora(TField* pf)
{
TDateTime dt = pf->AsDateTime;
TDateTime hh = dt.CurrentTime();
Word aa, mm, dd, h, m, s, ms;
DecodeDate( dt, aa, mm, dd );
DecodeTime( hh, h, m, s, ms);
dt = EncodeDate( aa, mm, dd );
dt = EncodeTime( h, m, s, ms );
ShowMessage( dt.DateTimeString() );
return dt;
}
//--------------------------------------------------------------------------
-
 
 

Re:TDateTime. How can I do...

"Romulo" < XXXX@XXXXX.COM >wrote in message
Quote
dt = EncodeDate( aa, mm, dd );
dt = EncodeTime( h, m, s, ms );
Your code is encoding the date and the *overriding* it with the time rather
than *appending* the time to the date. You need to use the '+' operator
instead:
dt = EncodeDate( aa, mm, dd ) + EncodeTime( h, m, s, ms );
Or, you could use the Time() function instead of CurrentTime() and
EncodeTime():
dt = EncodeDate( aa, mm, dd ) + Time();
Or, you can convert the TDateTime to an int instead of using DecodeDate() to
strip off the time portion quicker before appending the new time to it:
dt = TDateTime((int)(pf->AsDateTime)) + Time();
Or, you can use the ReplaceTime() function instead of the Decode/Encode...()
functions at all:
ReplaceTime(dt, Time());
Gambit
 

Re:TDateTime. How can I do...

Thanks. Really thank you.
That you have an excellent day.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >escribi?en el mensaje
Quote

"Romulo" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>dt = EncodeDate( aa, mm, dd );
>dt = EncodeTime( h, m, s, ms );

Your code is encoding the date and the *overriding* it with the time
rather
than *appending* the time to the date. You need to use the '+' operator
instead:

dt = EncodeDate( aa, mm, dd ) + EncodeTime( h, m, s, ms );

Or, you could use the Time() function instead of CurrentTime() and
EncodeTime():

dt = EncodeDate( aa, mm, dd ) + Time();

Or, you can convert the TDateTime to an int instead of using DecodeDate()
to
strip off the time portion quicker before appending the new time to it:

dt = TDateTime((int)(pf->AsDateTime)) + Time();

Or, you can use the ReplaceTime() function instead of the
Decode/Encode...()
functions at all:

ReplaceTime(dt, Time());


Gambit


 

{smallsort}