Parsing and storing date into Mongodb

Mongodb’s representation of datetime is – number-of-milliseconds-since-epoch. To parse a date string entered in a form

from datetime import datetime, time
# getting date from form
dt = datetime.strptime(request.form['date'], '%Y-%m-%d')
# adding date for a record
record = {}
# need to add time (0,0)
record['date'] = datetime.combine(dt, time())
view raw date_py_mongo hosted with ❤ by GitHub