AttributeError: ‘module’ object has no attribute ‘utcnow’

You are confusing the module with the type.

Use either:

import datetime

datetime.datetime.utcnow()

or use:

from datetime import datetime

datetime.utcnow()

e.g. either reference the datetime type in the datetime module, or import that type into your namespace from the module. If you use the latter form and need other types from that module, don’t forget to import those too:

from datetime import date, datetime, timedelta

Demo of the first form:

>>> import datetime
>>> datetime
<module 'datetime' from '/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/lib-dynload/datetime.so'>
>>> datetime.datetime
<type 'datetime.datetime'>
>>> datetime.datetime.utcnow()
datetime.datetime(2013, 10, 4, 23, 27, 14, 678151)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)