[Answered ]-Django comparing datetime.now with pub_date

1👍

If you are doing this for a template, use the timeuntil and timesince filters which are designed for this task.

1👍

import datetime

if some_datetime > datetime.datetime.now() + datetime.timedelta(days=10):
    return "some_date is greater than the current datetime plus 10 days"

See timedelta doc: http://docs.python.org/library/datetime.html#datetime.timedelta

0👍

from datetime import datetime

datetime_now = datetime.now()

‘datetime_now’ variable now has the current time.

Use this variable to compare with event start time and print or do relevant stuff for that condition.

for eg:

if event_start_time > datetime_now:
  print "upcoming"

Leave a comment