如何在sqlite中查询不同的日期格式 [英] how to query in sqlite for different date format
问题描述
我将 sqlite
用于移动和我的数据库中的本地数据库,我有列名为 RN_CREATE_DATE
的日期字段.我的 RN_CREATE_DATE
列值采用这种格式 'dd-mm-yy HH:MM:SS'
并且我想获取给定日期的数据.我在下面的数据库列和值中尝试过的确切查询是什么
I am using sqlite
for local database in mobile and in my database, I have date field with column name RN_CREATE_DATE
. My RN_CREATE_DATE
column value is in this format 'dd-mm-yy HH:MM:SS'
and I want to fetch data with given date. What will be the exact query for that I tried with below database column and value
**RN_CREATE_DATE
**RN_CREATE_DATE
2012-07-27 11:04:34
2012-07-27 11:04:34
2012-05-28 10:04:34
2012-07-22 09:04:34**
2012-05-28 10:04:34
2012-07-22 09:04:34**
SELECT RN_CREATE_DATE
FROM DISPOSITION
WHERE RN_CREATE_DATE=strftime('%Y', '2012-07-28 12:04:34')
但没有找到结果,请帮我解决这个问题.
but no result found, just help me out with this.
推荐答案
strftime
是这样工作的:
strftime
works like this:
sqlite> select strftime('%d-%m-%Y %H:%M:%S', datetime('now'));
2012-09-13 12:42:56
如果要在 WHERE
子句中使用它,请将 datetime('now')
替换为 YYYY-mm 中要匹配的日期时间-dd HH:MM:SS
格式.
If you want to use it in a WHERE
clause, replace datetime('now')
with the datetime you want to match in the YYYY-mm-dd HH:MM:SS
format.
示例:
SELECT *
FROM t
WHERE c = strftime('%d-%m-%Y %H:%M:%S', '2012-09-13 12:44:22');
-- dd-mm-YYYY HH:MM:SS YYYY-mm-dd HH:MM:SS
这篇关于如何在sqlite中查询不同的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!