mardi 7 avril 2015

SQLite Datetime before 24 hours query

I have a database table and storing a datetime column with the UTC datetime, iOS [NSDate date] is returning always a UTC datetime. It's all good about it.


I'm using FMDB to get the last 12 and 24 hours data with the following code.



[self.fmQueue inDatabase:^(FMDatabase *db)
{
NSString* queryCommand = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE %@ >= Datetime('?')", readingsTable, dateTimeRecordedColumn];
NSDate* dateBefore24Hours = [self.dateUtilities dateBySubtractingDays:1 forDate:[NSDate date]];
WEELogDebug(@"Date before 24 hours: %@", dateBefore24Hours);
FMResultSet* result = [db executeQuery:queryCommand, dateBefore24Hours];
if (completionblock)
{
completionblock([self readingsArrayFromResultSet:result]);
}
}];


What I need to accomplish is retrieve all data that has a date after the dateBefore24Hours variable. The debug message shows the correct value, for example [NSDate date] now before 24 hours is, Date before 24 hours: 2015-04-06 15:28:08 +0000, so I should get al the records until 2015-04-07 15:28:08 +0000 with the above query, but I don't.


With SQLite Studio I provide you with the records I have at the moment in the database.


Records in SQLite


Aucun commentaire:

Enregistrer un commentaire