Sqlite3 - Insert Query with date field lazarus / 43-Android ---------------------------------------------------------------------- biologic · 2025-10-19 16:38 Hello all, Someone knows how to Insert a record with a date field, with the text format like 'YYYY-MM-DD' ? I currently use InsertIntoTable with the INSERT statement. The record is not added. Thank you. ---------------------------------------------------------------------- biologic · 2025-10-19 17:08 This is what I currently have : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule3.SaveButtonClick(Sender: TObject);var insertstmt : string;begin  // Save record en Close Form   ShowMessage('Name  '+EditName.Text);  ShowMessage('Desc  '+EditOmschrijving.Text);  ShowMessage('Datumstring '+datumstring);  ShowMessage('Uur '+EditUur.Text+':'+EditMinuten.Text);    insertstmt:='INSERT INTO AFSPRAKEN (NAAM, DESCRIPTION, DATUM, TIJD) VALUES ('''+EditName.Text+''', '''+EditOmschrijving.Text+  ''', '''+datumstring+''', '''+EditUur.Text+':'+EditMinuten.Text+''');';   //if (dmDB.DB.ExecSQL(insertstmt))  if (dmDB.DB.InsertIntoTable(insertstmt))  then   ShowMessage('Record added')  else   ShowMessage('Record not added');   Close;   // Form 3 end; ---------------------------------------------------------------------- BlueIcaro · 2025-10-20 07:29 Hello, you can try with FormatDateTime, take a lookt: Code: [Select]program Project1; uses   SysUtils; var   Today: TDateTime; begin   Today := Now();   Writeln ('Now : ',FormatDateTime('YYYY-MM-DD',Today)); //this returns 2025-10-20   Readln(); end.  /BlueIcaro ---------------------------------------------------------------------- rvk · 2025-10-20 07:38 If the record is not added... do you get the "Record not added" message? And if you do... how does your InsertIntoTable look like? Why don't you produce a better error message when you get an exception (DB error). From the DB error you can see what the problem is exactly. Also... show what the exact content is of the string insertstmt. (put it in a showmessage before executing) It might give you a clue. Finally, I hope this code is for personal use or still needs to be improved (because of the sql injection possibility and you might want to use number for date or even DATETIME for a complete datetimestring). ---------------------------------------------------------------------- Thaddy · 2025-10-20 08:09 Or use datetimetotimestamp: https://www.freepascal.org/docs- html/rtl/sysutils/datetimetotimestamp.html ---------------------------------------------------------------------- cdbc · 2025-10-20 08:27 Hi N.th option: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /// sql =  create table ...(..., yourdate   bigint, .../// sql = 'insert into ... values(... ,:pdate, ...);'Query1.ParamByName('pdate').AsLargeInt:= DateTimeToUnix(Now); /// note: yourdate = largeint - ->  UnixToDateTime();   DateTimeToUnix(); ///These functions above come from 'DateUtils' Regards Benny ---------------------------------------------------------------------- Zvoni · 2025-10-20 10:49 Quote from: rvk on October 20, 2025, 09:38:48 amIf the record is not added... do you get the "Record not added" message? And if you do... how does your InsertIntoTable look like? Specifically if it's a Function returning a Boolean, nevermind is the Result set in that Function? Everything said: Commit/CommitRetaining missing somewhere? And where is the value for "datumstring" coming from? ---------------------------------------------------------------------- biologic · 2025-10-24 21:09 Everything is working now. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if fDB = nil    then gApp.CreateForm(TfDB,fDB);  fDB.Init;    <--- this line I forgot to do ---------------------------------------------------------------------- biologic · 2025-10-24 21:25 How can I improve my code against SQL injection? ---------------------------------------------------------------------- dseligo · 2025-10-24 21:41 Quote from: biologic on October 24, 2025, 11:25:58 pmHow can I improve my code against SQL injection? Use parameters, like in reply #5.