I've got a database filled with data, together with a time and date string, e.g. Tue, 21 Sep 2010 14:16:17 +0000

What I must have the ability to do is extract various documents (records) in the database in line with the time contained inside the date string, Tue, 21 Sep 2010 14:16:17 +0000.

In the above date string, wouldso would I personally use python and regex to extract documents which have time 15:00:00? I am using MongoDB incidentally, along with Python.

Thanks ahead of time, James Eggers

I'm not sure MongoDB, but should not something similar to the work?

SELECT * FROM Database WHERE Date LIKE '%15:00:00%'

For those who have to start dating ? string, the only real put it consists of colons would be the time area of the date, to ensure that ought to be adequate with no regex. It might be better, obviously, should you have had a real timestamp rather than a string inside your date area.

To be sure using the other poster. Though this does not solve your immediate problem, for those who have any treatments for the database, you need to you should consider developing a time/column, with whether DATE or TIMESTAMP datatype. That will build your system a lot more robust, &lifier completely steer clear of the problem of attempting to parse dates from string (an naturally fragile technique).

You should use $where:

db.collection.find({$where: "var d = new Date(this.dateProperty); return d.getUTCHours() == 15 && d.getUTCMinutes() == 0 && d.getUTCSeconds() == 0"})

Or regular expression:

db.collection.find({dateProperty: /.*15:00.*/})

The 2nd could be a little faster than first but both is going to be relatively slow. To speedup stuff you would store dates in built-in date format. Also if you want to query on datetime components attempt to add indexable date representation for example {y:2010,m:9,d:21,h:14,i:16,s:17} (qualities rely on your query needs, should you only have to query by hour you'd have {h:14}). You'll be able to have index per each component.