Amartya Gaur
Amartya Gaur

Reputation: 705

How to get the next day's date in django.utils.timezone

I want to set the status of a task as due today, due tomorrow, overdue or upcoming if the date that the task is due on is today, yesterday (or before that) or tomorrow (or after tomorrow)

This is what I do to compare today :

if (timezone.now().date == k["due_on"].date) :
    task.status = "due today"

I want to write similar logics for future or past something like this:

if (k["due_on"].date == tomorrow) :
    task.status = "due tomorrow"

and so on.

Please help

Upvotes: 2

Views: 2980

Answers (1)

Exprator
Exprator

Reputation: 27523

from datetime import timedelta

tomorrow = timezone.now() + timedelta(days=1)

if (k["due_on"].date == tomorrow.date()) :
    task.status = "due tomorrow"

you can use this to check next days date

Upvotes: 8

Related Questions