[Lazarus] Conversion from TField.AsDateTime to string
Leonardo M. Ramé
l.rame at griensu.com
Sat Sep 10 21:45:01 CEST 2011
On 2011-09-10 11:43:02 +0200, Michael Van Canneyt wrote:
>
>
> On Fri, 9 Sep 2011, Leonardo M. Ramé wrote:
> >
> >To convert the JSON string to TDateTime, I use StrToFloat, then I show the result using:
> >
> >FormatDateTime('YYYY-MM-DD', myDate);
> >
> >On Linux I get: 2011-08-17 09:25:24
> >On Win32 I get: 34248-02-16 00:00:00
> >
> >Why the difference?.
>
> Probably because strtofloat takes into account localization settings.
>
> You should use val() from the system unit. It ignores localization.
>
> Michael.
Here's more info. I didn't noted the field type on the PostgreSql
database is "timestamp without time zone", I thought it was type Date.
To get the value as TDateTime, I use myField.AsDateTime, then convert
this value to JSON this is server side. On client side, I receive the
string, then convert it to Variant, and using RTTI I assign the value to
a published property of an object.
To assign the variant value to the published property of tipe TDateTime, I use this:
PDouble(P)^ := VarAsType(lValue, varDouble);
On Delphi this works as expected. Could this assignment be causing the
wrong conversion?.
--
Leonardo M. Ramé
http://leonardorame.blogspot.com
More information about the Lazarus
mailing list