Prometheus
Prometheus

Reputation: 33655

AttributeError: type object 'datetime.date' has no attribute 'now'

Using these lines of code:

from datetime import date

date_start = date.now()

I'm getting this error:

AttributeError: type object 'datetime.date' has no attribute 'now'

How can I solve this?

Upvotes: 13

Views: 31258

Answers (2)

Bhuwan Joshi
Bhuwan Joshi

Reputation: 41

This works:

import datetime

datetime.date.today()

Upvotes: 4

Aldarund
Aldarund

Reputation: 17621

You need to use

 import datetime

 now = datetime.datetime.now()

Or if you are using django 1.4+ and have timezone enabled you should use

 django.utils.timezone.now()

Upvotes: 31

Related Questions