Problems with Time and DateTime Fields

Forum related to MySQL

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Pedali
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 09.08.2007, 09:07

Problems with Time and DateTime Fields

Post by Pedali »

Hi all,
I'm working with Lazarus 0.9.20 Beta and Zeos lib 6.6.1Beta on a Debian System. Database server is a Mysql 5.0.32.

Storing a date and a time in a DateTime field works ok. But if I read it with ZQuery1.fieldByName('startTime').asString I get the time minus one minute.
Example:
The date time in the database is '2007-08-15 11:00:00'
but I get following '2007-08-15 10:59'

Unfortunately I cannot reproduce it all the time but I can say that it happens independent of the function (asString, asDateTime) with DateTime-fields and Time-Fields.

Until now I wasn't able to test it with several mysql versions or older/newer versions of zeos lib or Lazarus. I searched several forums and "googled" several days but without any result. So I'm really sorry, if the mistake is on me, missing something important.

I hope someone has a solution or an idea because it is really annoying for me to use varchar fields for storing of dates and/or times ;)

Peter
Pedali
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 09.08.2007, 09:07

Update

Post by Pedali »

Hi all,
I found a solution to get the time and date correct out of the DB.
I preformat the data ("startDateTime") and read it as a new field("startDateTime_formated").

Example-Query:

Code: Select all

with ZQuery do
begin
    SQL.Clear;
    SQL.Add('SELECT *, date_format(startDateTime,"%d-%m-%Y %H:%i:%s")  AS startDateTime_formated FROM appointmentTable');
     Open;
     MyCorrectStartDateTime:=FieldByName('startDateTime_formated').AsDateTime;
end; 
Anyway I would be glad to get another solution for this problem, because in my opinion it must be possible to get the correct time out of the database the less complex way too.

Peter
Post Reply