Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 421
Prometheus Avatar asked Mar 15 '13 14:03

Prometheus


2 Answers

This works:

import datetime

datetime.date.today()
like image 198
Bhuwan Joshi Avatar answered Oct 29 '22 03:10

Bhuwan Joshi


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()
like image 29
Aldarund Avatar answered Oct 29 '22 05:10

Aldarund