13

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?

2 Answers 2

31

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()
Sign up to request clarification or add additional context in comments.

2 Comments

django.utils.timezone.now() still give me 2013-03-15 00:00:00 just the date
Where should I put ' django.utils.timezone.now()' ? @Prometheus
4

This works:

import datetime

datetime.date.today()

1 Comment

That doesn't give the current time, only the date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.