我从这个链接找到了这个:
http://www.sqlite.org/datatype3.html
1.2 Date and Time Datatype
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.date and time functions.
我对应该使用哪个感到有点困惑。我正在创建一个 Windows 窗体 C# 应用程序,并将使用内置的 DateTime
控件。
哪个选项最适合我?我认为 TEXT
会,但也许我错了。我是 SQLite 新手。
谢谢。
最佳答案
我假设您使用的是 System.Data.SQLite ?即使 SQLite 本身无法识别日期时间数据类型,该数据提供程序也能识别它。
例如,如果您使用 SQLiteDataAdapter 通过 select 语句填充数据表,如果列的数据类型是日期时间,则返回的数据列将为日期时间。
提供程序有一个限制:当您的选择包含多个表时,它无法猜测数据类型。在这种情况下,您可以通过像这样在查询之前预先声明返回的数据类型:
types [integer], [text], [boolean], [datetime];
select A.id, A.subject, B.isactive, B.due_date from ...
提供程序将数据存储为文本,如 2009-04-01 17:42:38.828125
。 SQLite 可以使用这种格式,例如,您可以使用以下方法计算第二天:
select datetime('2009-04-01 17:42:38.828125', '+1 days');
编辑:您将数据类型指定为日期时间,如下所示:
create table C ( d datetime );
关于c# - 在 SQLite 中保存日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4063602/