Forum > Databases

SQLite3 Date Problem

<< < (2/11) > >>

Handoko:
I am not sure it will help or not. I just want to share how I handle date time data in SQLite.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  DateTimeFormat = 'dd-mm-yy hh:nn:ss'; function TimeFormatted(T: TDateTime): string;begin  Result := FormatDateTime(DateTimeFormat, T);end;
The data time data will be stored as REAL data type in SQLite. And each time when showing it to user, I always call TimeFormatted. Because I consistently use DateTimeFormat, my code works. And I prefer to use TStringGrid, because I can format and show the data in whatever way I like.

Note:
I guess you already know, TDateTime actually is Double in Pascal.

paweld:
Actually, I forgot that “/” is a replacement for the date separator. You need to take the “/” in quotation marks.
Sample in attachment.

Thaddy:
Handoko provided a better example: store it as TDatetime and convert as necessary.
Because the conversion code has the correct TFormatsettings for the language.

pat03uk:
I’m storing the date as a string.
My understanding of SQLite is that you can store as string, integer or real - how do you store as TDate or TDatetime?
Pat

Handoko:
Didn't I already say, TDateTime actually is Double in Pascal?

Storing date data as string (in SQLite) may work too, but you need to extra carefully consistently format the data correctly. Extra work, not worth in my opinion.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version