TZQuery.AsDateTime property

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
peterd
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 24.02.2010, 08:06

TZQuery.AsDateTime property

Post by peterd »

Hi,

Using SQLite v3.6.22
ZeosLib v6.6.6
Delphi 6

I have created a simple SQLite table called user with one DATETIME field called t.
When I try to assign a TDateTime variable dt to one of the field values using

dt := ZTable1.FieldByName ('t').AsDateTime;

there is no problem.

Actually I want to extract the maximum value of t from the table so I tried

ZQuery1.SQL.Text := 'select max (t) as maxt from user';
ZQuery1.Open;
dt := ZQuery1.FieldByName ('maxt').AsDateTime;

Now I get a conversion error: '2007-11-01 20:33:41 is not a valid date and time'.

Does anyone know what I'm doing wrong?

Thanks

Peter
Wild_Pointer
Expert Boarder
Expert Boarder
Posts: 164
Joined: 18.03.2008, 13:03
Contact:

Post by Wild_Pointer »

Hello, peterd,
This is wild guess, but what date format is used on your computer (locale). It seems that the error is related to different formats on your computer and the DB server. Try changing your locale date time formate to YYYY-MM-DD HH:NN:SS. If that helps, then it is for sure date/time conversion error.

Good luck to you!
peterd
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 24.02.2010, 08:06

Post by peterd »

Thank you W_P for your reply.

You're right about the local settings. But isn't it strange that a property as AsDateTime depends on the local setting. As far as I know one of the reasons the TDateTime type is used is not to depend on the local settings.
Another point is that TZTable doesn't seem to have this problem.

Maybe somebody knows if it's possible to change the local settings temporarely (during the execution of 'AsDateTime' assignment).

Thanks

Peter
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Not sure if sqlite can return the result of max(t) as a datetime value to zeoslib. That may be why getting asdatetime is impossible.

You can try to debug at TZSQLiteResultSet.Open ?

Mark
Image
peterd
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 24.02.2010, 08:06

Post by peterd »

Mark,

ZQuery1.FieldByName ('maxt').AsDateTime works only if the short date format is set to yyyy-mm-dd, which doesn't make it very useful in practice.

A workaround may be:

var
OldShortDateFormat: String;

OldShortDateFormat := ShortDateFormat;
ShortDateFormat := 'yyyy-mm-dd';
dt := DataMod.qEvent.FieldByName ('start').AsDateTime;
ShortDateFormat := OldShortDateFormat;

This works on my 'dutch' PC. Still have to check other languages.

Peter
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Peter,

The question remains: is this because the field format returned by sqlite is different for "select max(t) from" and "select t from"?
Sounds like this must be the reason as the result for the second query is correct.

Please debug in the procedure I pointed you to.

If the datatype is different: is there a function to force the resultset datatype like cast() in SQLite?

Mark
(BTW : you can use my email if you want assistance in dutch)
Image
peterd
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 24.02.2010, 08:06

Post by peterd »

Marc,

What is your email address?

Peter
Post Reply