gpt4 book ai didi

c# - 在 SQLite 中保存日期?

转载 作者:行者123 更新时间:2023-11-30 12:17:16 25 4
gpt4 key购买 nike

我从这个链接找到了这个:

http://www.sqlite.org/datatype3.html

1.2 Date and Time Datatype

SQLite does not have a storage classset aside for storing dates and/ortimes. Instead, the built-in Date AndTime Functions of SQLite are capableof storing dates and times as TEXT,REAL, or INTEGER values:

TEXT as ISO8601 strings ("YYYY-MM-DDHH:MM:SS.SSS").

REAL as Julian daynumbers, the number of days since noonin Greenwich on November 24, 4714 B.C.according to the proleptic Gregoriancalendar.

INTEGER as Unix Time, thenumber of seconds since 1970-01-0100:00:00 UTC. Applications can choseto store dates and times in any ofthese formats and freely convertbetween formats using the built-indate 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com