python - Extracting Date and Time info from a string. -


i have database full of data, including date , time string, e.g. tue, 21 sep 2010 14:16:17 +0000

what able extract various documents (records) database based on time contained within date string, tue, 21 sep 2010 14:16:17 +0000.

from above date string, how use python , regex extract documents have time 15:00:00? i'm using mongodb way, in conjunction python.

you can 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 second can bit faster first both relatively slow. speedup things store dates in built-in date format. if need query on datetime components consider adding indexable date representation such {y:2010,m:9,d:21,h:14,i:16,s:17} (properties depend on query needs, if need query hour have {h:14}). can have index per each component.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -