如何从SQLite中的日期时间结果列中检索日期部分? [英] How to retrieve the Date part out of a Datetime result column in SQLite?
本文介绍了如何从SQLite中的日期时间结果列中检索日期部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datetime类型的列,我想从中检索只有日期。是否还有这样做?
I have a column of datetime type from which I would like to retrieve only the date. Is there anyway to do this?
以前是一个时代值,我将它转换为datetime。
Previously it was an epoch value where I convert it to datetime .
这是一个示例结果:
smbd|ip address|1082|ip address|"2011-04-26 18:40:34"
我尝试了以下命令,但它产生负/零结果
I have tried the following commands, but it yields negative / zero results
SELECT DATE(datetime) from attacked_total;
SELECT STRFTIME('%Y-%m-%d', datetime) FROM attacked_total;
SELECT DATETIME('%Y-%m-%d', datetime) FROM attacked_total;
SELECT DATE('%Y-%m-%d', datetime) FROM attacked_total;
推荐答案
您可以使用 DATE function。
You can use the DATE function.
示例
> select date('2011-04-26 18:40:34')
> 2011-04-26
您只能使用strftime获取日期,
You can get only the day with strftime,
> select strftime('%d', '2011-04-26 18:40:34')
> 26
这篇关于如何从SQLite中的日期时间结果列中检索日期部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文