strftime function in SQLite does not work

元气小坏坏 提交于 2019-12-06 12:05:31

问题


Hi, I am using the following query but it does not work,

SELECT strftime('%m',Since) AS Month FROM Dates

Type of Since column is DATETIME, but the result is shown an empty Month column without any error.


回答1:


strftime isn't broken, it just doesn't understand the format of the datestamps in your database.

SQLite version 3.7.9 2011-11-01 00:52:41
sqlite> create table dates (id int, d datetime);
sqlite> insert into dates (id,d) values (1, date('now'));
sqlite> insert into dates (id,d) values (2, 'bad date');
sqlite> insert into dates (id,d) values (3, NULL);
sqlite> insert into dates (id,d) values (4, datetime('now'));
sqlite> select * from dates;
1|2012-09-23
2|bad date
3|
4|2012-09-23 04:31:36
sqlite> select id, strftime('%m', d) from dates;
1|09
2|
3|
4|09


来源:https://stackoverflow.com/questions/12549671/strftime-function-in-sqlite-does-not-work

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