Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...