I have a DATETIME field. I would like to select all the records that have been updated in the last week. Right now I’m using this query:
SELECT SUM(mins_spent) as time_sum FROM todos WHERE lastUpdate >= '2008-12-22' AND lastUpdate <='2008-12-28'
But the results i get seem to be different depending on time of the day, e.g on 7 PM I might get 17 hours and on 11 PM I’l get 14 hours even though it should be increasing, not decreasing. I was thinking of changing the query to:
SELECT SUM(mins_spent) as time_sum FROM todos WHERE lastUpdate >= '2008-12-22 00:00:00' AND lastUpdate <='2008-12-28 00:00:00'
Would it help at all? Suggestions please..
'2008-12-22'should equal'2008-12-22 00:00:00'.Are you wanting ’till end-of-day 28th?’ If so, add
23:59:59to the 2nd date.Alternatively, you can use
lastUpdate < '2008-12-29'.How are you tracking changes to an existing ToDo?
INSERTand/orDELETE? OrUPDATE?If you’re
DELETE‘ing records upon ‘completion,’ you’ll just have fewer records.If you’re
UPDATE‘ing, are you allowing dates to change to beyond the current week? If so, they’ll be removed from your results.To see what’s happening, You may try grabbing a few aggregates on the table,
mins_spent, andlastUpdate(mark down the values and run occasionally to see how they change).