日期和时间数据类型
SQLite 能够将日期和时间存储为 TEXT、REAL 或 INTEGER 值:
- TEXT 作为 ISO8601 字符串(“YYYY-MM-DD HH:MM:SS.SSS”)。
- REAL 作为儒略日数,即自公元前 4714 年 11 月 24 日格林威治中午以来的天数。根据公历。
- INTEGER 作为 Unix 时间,自 1970-01-01 00:00:00 UTC 以来的秒数。
例如,此处显示 REAL 和 INTEGER 部分。
修改后的 SQLite3 包装器测试文件:uTestSqlite
sSQL := 'CREATE TABLE testtable ([ID] INTEGER PRIMARY KEY,[OtherID] INTEGER NULL,';
sSQL := sSQL + '[Name] VARCHAR (255),[Number] FLOAT,[Date] INTEGER, [notes] BLOB,
[picture] BLOB COLLATE NOCASE);';
sldb.execsql(sSQL);
sldb.execsql('CREATE INDEX TestTableName ON [testtable]([Name]);');
//begin a transaction
sldb.BeginTransaction;
sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Date) VALUES ("Some Name", 4,
julianday("now"), strftime("%s","now"));';
sldb.ExecSQL(sSQL);
sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Date,Notes) VALUES ("Another Name",12,
julianday("2013-03-01"),strftime("%s","2013-03-01"), "More notes");';
sldb.ExecSQL(sSQL);
//end the transaction
sldb.Commit;
[...]
//query the data
sltb := slDb.GetTable('SELECT * FROM testtable');
if sltb.Count > 0 then
begin
//display first row
updateFields;
end;
显示值:
procedure TForm1.updateFields;
var
Notes: string;
myDate :TDateTime;
begin
ebName.Text := sltb.FieldAsString(sltb.FieldIndex['Name']);
ebID.Text := inttostr(sltb.FieldAsInteger(sltb.FieldIndex['ID']));
if TryJulianDateToDateTime(sltb.FieldAsDouble(sltb.FieldIndex['Number']),myDate)
then
ebNumber.Text := DateTimeToStr(myDate)
else
ShowMessage('Not a valid Julian date');
myDate:=UnixToDateTime(sltb.FieldAsInteger(sltb.FieldIndex['Date']));
ebDate.Text := DateTimeToStr(myDate);
[...]
end;
Output:
![enter image description here](https://i.stack.imgur.com/LEPRr.jpg)
在你的问题中DB.ExecSql('CREATE TABLE Tags (..., Born Date NULL,...);');
替换为DB.ExecSql('Insert into Tags (....) VALUES (...
+ quotedStr(frmTag.edtBorn.Text)
with
'strftime("%Y-%m-%d","'+frmTag.edtBorn.Text+'")'
的价值frmTag.edtBorn.Text
一定像1975-10-21
您可以通过以下方式获取它:
ebDate.Text := sltb.FieldAsString(sltb.FieldIndex['Born']);