[Answered ]-Why can't I not use the now variable in bug fix for django poll tutorial part 5

1πŸ‘

βœ…

The easiest way to understand the difference is with some examples:

In [4]: timezone.now() == timezone.now()
Out[4]: False

In [5]: a = timezone.now()
In [6]: a == a
Out[6]: True


In [11]: print timezone.now() - timezone.now()
-1 day, 23:59:59.999984

In [12]: print a - a
0:00:00

You should notice each time you call timezone.now(), you get a different time.

πŸ‘€user1301404

1πŸ‘

The first function gets the current time and then saves that value in the variable now. This value is then used twice (unchanged) in the next line.

The second function however calls timezone.now twice. This means that you will get two different times; one for each call. Granted they will only be off by a few milliseconds at the most, but it is still a difference.

Remember that each time you call timezone.now, it will return the current time. Consequentially, no two calls will return the same value.

πŸ‘€user2555451

Leave a comment