gpt4 book ai didi

sqlite - SQLite 中的 strftime 函数不起作用

转载 作者:行者123 更新时间:2023-12-03 15:47:22 32 4
gpt4 key购买 nike

嗨,我正在使用以下查询,但它不起作用,

SELECT strftime('%m',Since) AS Month FROM Dates
Since 的类型列是 DATETIME ,但结果显示为空的 Month 列,没有任何错误。

最佳答案

strftime 没有损坏,它只是不理解数据库中日期戳的格式。

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

关于sqlite - SQLite 中的 strftime 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12549671/

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