Question: ```
from django.utils import timezone

good = Goods.objects.get(id=num)
now = timezone.now()

print(good.create_time)
print(now)

```

How to compare these whether they are by one day.

```
2016-12-01 10:21:32.746505+00:00
2016-12-01 10:24:08.906268+00:00

```

Answer: 
Use a [timedelta](https://docs.python.org/2/library/datetime.html#timedelta-objects):

```
d1 = datetime(year=2016, month=12, day=1)
d2 = datetime(year=2016, month=12, day=2)

abs(d2 - d1) < timedelta(days=1)

```

Or if you just want to compare the day, you can access it from the `.day` attribute:

```
d1.day # 1
d2.day # 2

```
You'll have to [create a new `timedelta`](http://docs.python.org/library/datetime.html#datetime.timedelta) with the specified amount of time:

```
d > timedelta(days=1)

```

Or this slightly more complete script will help elaborate:

```
import datetime
from time import sleep

start = datetime.datetime.now()
sleep(3)
stop = datetime.datetime.now()

elapsed = stop - start

if elapsed > datetime.timedelta(days=1):
    print "Slept for > 1 days"

if elapsed > datetime.timedelta(seconds=1):
    print "Slept for > 1 second"

```

Output:

`Slept for > 1 second`