What is the easiest way in ios app to compare datetime string in sqlite3.
I store the datetime string in following way.
NSDateFormatter* df=[[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString* dtString=[df stringFromDate:[NSDate date]];
then I’m inserting dtString into the table. So after i want to retrieve all rows for example only for last two days.
sqlite3 doesn’t contain a
DATETIMEtype so you need to think of ways of encoding it.If you want to use the date column in a
WHEREclause then you could store thetime_treturned fromgmtime(time(NULL))(i.e. the time now, since UNIX epoch) and then use some simple clause to get those rows:And binding that
?togmtime(time(NULL)) - 60**60*24*2EDIT: If you want to stay completely in Objective-C, then the same date value can be determined from an
NSDateobject using: