Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

sql - how to query in sqlite for different date format

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

2012-07-27 11: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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

strftime works like this:

sqlite> select strftime('%d-%m-%Y %H:%M:%S', datetime('now'));
2012-09-13 12:42:56

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.

Example:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...