How to format date and time values for SQLite?

我们两清 提交于 2019-12-04 15:23:58

A date, time and datetime field will actually all store datetime, it just depends on what you insert into it, and they will all work with date strings.

You can

insert into atable values("2010-11-16","14:12:22","2010-11-16 14:12:22");

or you can actually just insert "2010-11-16 14:12:22" into all the fields and then select them back with:

select date(adatefield), time(atimefield), datetime(adatetimefield) from atable;

If however you want to make sure that the fields only contain exactly a date,time or datetime and you're inserting from variables, then you can

insert into atable values(date(thedate),time(thedate),datetime(thedate));

Sqlites typelessness makes some things really easy, but can confuse or complicate some other things.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!