DATETIME PLZ lazarus / 16-Databases ---------------------------------------------------------------------- hinst · 2014-04-25 15:37 If I retrieve a field of type DATETIME using AsString property, will the db library then convert it to TDateTime and then to string, or will it extract it directly as string? ---------------------------------------------------------------------- marcov · 2014-04-25 17:55 In general TDatetime probably. ---------------------------------------------------------------------- LacaK · 2014-04-25 18:23 @hinst: can you provide more details about your question. Which DB, which client library, which client database components ? ---------------------------------------------------------------------- hinst · 2014-04-25 18:43 I am having in mind sqldb aka fcl-db, I use no visual components, I do things in code TField has properties: AsString and AsDateTime I suppose that sqldb receives date as string, then converts it to TDateTime. Then AsString property perhaps does not convert TDateTime to string, but provides the string as is instead I currently work with MySQL database ---------------------------------------------------------------------- engkin · 2014-04-25 18:57 TField.AsDataTime is going to raise an exception: Code: [Select]function TField.GetAsDateTime: TDateTime; begin   raise AccessError(SdateTime); end; While TDateTimeField and TDateField would trust you and read raw data into @Result: Code: [Select]function TDateTimeField.GetAsDateTime: TDateTime; begin   If Not GetData(@Result,False) then     Result:=0; end; As for TStringField, it does convert String to TDateTime: Code: [Select]function TStringField.GetAsDateTime: TDateTime; begin   Result:=StrToDateTime(GetAsString); end; ---------------------------------------------------------------------- mangakissa · 2014-04-26 06:38 Quote from: hinstI suppose that sqldb receives date as stringIt depends how your date is saved in your table. If it is a datetime field, it will be saved as double. Retreaving the date via SQLdb will be convert with AsDateTime or AsString. Even .AsFloat should work. If the date is saved as a string, the conversing could probably fail if the format is not correct. ---------------------------------------------------------------------- hinst · 2014-04-26 08:57 So MySQL sends date as Double, in FPC TDateTime is Double, but encodings differ? ---------------------------------------------------------------------- LacaK · 2014-04-26 10:53 If we are speaking about MySQL then: - MySQLConnection calls MySQL client library API to get result row data. In current implementation this row data are returned as PChar so MySQLConnections translated "string representation" of DateTime into TDateTime (double) - This TDateTime value is stored in local record buffer maintained by TBufDataSet (TSQLQuery) - When you request Field.AsDateTime then this value is simply moved as is - When you request Field.AsString then  this value is simply moved as is + FormatDateTime() is used ---------------------------------------------------------------------- hinst · 2014-04-26 11:02 I see. I was hoping that original string representation of datetime returned by MySQL API is stored