简体   繁体   中英

How to store a date in a SQLite3 schema for Flask?

I am aware that 'datetime' is not a valid data type for SQLite, but I'm not quite sure what to replace it with. Take for example the following statements, would I store it as text like the others? If so, how would I then manipulate that later on, as a date?

drop table if exists entries;
create table entries (
  id integer primary key autoincrement,
  title text not null,
  'text' text not null,
  date_created 
);

I am aware that 'datetime' is not a valid data type for SQLite

SQLite's flexibility results in virtually any column type being valid eg

CREATE TABLE weidrcolumntypes (column1 rumplestiltskin, column2 weirdtestcolumn, column3 etc)

is valid and will create a table with 3 columns (4 with rowid column) :-

在此处输入图片说明

SQLite's flexibility also allows any value to be stored in any column (an exception being the rowid , for tables that are not defined using WITHOUT ROWID , where the value must be an INTEGER).

A more comprehensive answer (tagged for Android but the principles still apply) is here .

This may also be of interest .

So in brief any column type would be able to handle/store datetime.

Take for example the following statements, would I store it as text like the others?

As per above even as it is the code you have would be usable. You may wish to specify a column type of TEXT or INTEGER .


If so, how would I then manipulate that later on, as a date?

As for storing date time, Integer, Long or String could be used, the latter having the complimentary Date And Time Functions .

As such, you could do much of the manipulation within your queries which would be language independent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM