Johnny
Johnny

Reputation: 69

django. Get only current day. Only day without time

I want to get current day for now. Only day. For example today is 20-March i need use it in my queryset

query = self.filter(Q(busyrooms__end_date__day=datetime.now().date()),
                    Q(reservedrooms__end_date__day=datetime.now().date()))

Tried to use datetime.now().date() but i got error

TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.date'

Upvotes: 4

Views: 6589

Answers (2)

anjaneyulubatta505
anjaneyulubatta505

Reputation: 11705

In django most of the cases we use timezone. so, it's recommended to use timezone .

from django.utils import timezone

timezone.now().date()
timezone.now().day

Upvotes: 7

Avinash Raj
Avinash Raj

Reputation: 174844

You can get the current day from datetime_obj by accessing the day attribute of datetimeobj like datetime.now().day

Upvotes: 8

Related Questions