[Lazarus] Conversion from TField.AsDateTime to string

Michael Van Canneyt michael at freepascal.org
Sat Sep 10 11:43:02 CEST 2011



On Fri, 9 Sep 2011, Leonardo M. Ramé wrote:

> I'm working with a CGI that returns data as JSON. Then I read this data
> from a GTK2 or Win32 client.
>
> The JSON may have fields containing dates, that are populated from a
> database using TSqlQuery, then converted to TDateTime using
> Field.AsDateTime and added to a JSONObject using TJSonObject.Add(.., ..).
>
> The result is something like this:
>
> {
>   "apellido" : "BLANDINO",
>   "nombres" : "ALBERTO",
>   "fecha" : 40772.3926388889
> }
>
> On client side, instead of receiving 40772.3926388889 I can see this
> while debugging:
>
> ' 4.07714066087963E+004'
>
> I don't know, but maybe this is a GDB conversion issue.

Most likely.

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


More information about the Lazarus mailing list