Android : SQLite Select all records for today and yesterday [duplicate]

on Tuesday, September 30, 2014



This question already has an answer here:




I am trying to get all records from sqlite database based on today and yesterday.


The datatype of my_date_time column is Text in database, and the format in which the date and time is stored is:



E MMM dd HH:mm:ss Z yyyy



so all my dates are stored in this format



Sun Aug 24 21:44:27 GMT+00:00 2014
Sun Aug 25 21:44:27 GMT+00:00 2014
Sun Aug 26 21:44:27 GMT+00:00 2014
Sun Sep 28 21:59:56 GMT+00:00 2014
Sun Sep 28 18:58:08 GMT+00:00 2014
Mon Sep 29 19:29:29 GMT+00:00 2014
Mon Sep 29 20:29:29 GMT+00:00 2014
Tue Sep 30 13:30:12 GMT+00:00 2014


Now I want to select all records according to today or yesterday.


For Yesterday I tried this:



SELECT id, title, my_date_time FROM my_table WHERE date(my_date_time) < date('now','-1 day');


For Today, I tried this:



SELECT id, title, my_date_time FROM my_table WHERE date(my_date_time) < date('now');


Both returns 0 rows. Could you please tell me what am I doing wrong here?


What is causing the problem here, column datatype(TEXT), my_date_time format(E MMM dd HH:mm:ss Z yyyy) or my above queries?


0 comments:

Post a Comment