I am trying to convert the date into datetime with some specific time with combine
method but it didn't worked. It throws AttributeError.
AttributeError: module 'datetime' has no attribute 'combine'
import datetime
from dateutil.relativedelta import relativedelta
from django.contrib.admin.models import LogEntry
from django.utils import timezone
now = timezone.now()
print(now)
required_date = now.date() - relativedelta(months=3) # 3 months older date
print(required_date)
required_datetime = datetime.combine(required_date, datetime.time(09,00,00))
print(required_datetime)
LogEntry.objects.filter(action_time__range=(required_datetime, now)).delete()
try it like this
datetime.datetime.combine()
you want to use the combine
method of the datetime
object that is in the datetime
module
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.