[Answer]-Django. Check if its another day

1👍

✅

You can do something like this:

from datetime import datetime, timedelta

def some_view(request):
    now = datetime.now()
    # using a timedelta avoids having to know about length of months etc:
    same_time_tomorrow = now + timedelta(days=1)
    start_of_tomorrow = same_time_tomorrow.replace(
        hour=0,
        minute=0,
        second=0,
        microsecond=0
    )
    # returns a timedelta object:
    difference = start_of_tomorrow - request.user.last_points_added
    if difference.days > 0:
        # add points

Leave a comment