[Answer]-"An integer is required" datetime field

0👍

Try this,

day_ago = datetime.date.today() - datetime.timedelta(days=1)
yesterday = datetime.datetime(day_ago.year, day_ago.month, day_ago.day)
hist_obj = Events.objects.filter(uploader = request.user,
        start_date__lt = yesterday)
return render_to_response('history.html', {'history_obj':hist_obj})

1👍

This code is confusing. yesterday and month are both datetimes, because that’s how you defined them in lines 2 and 4. So what are you trying to achieve in the code that throws the error? As the message says, you can’t pass a datetime as the day or month parameter to construct another datetime. Especially as, surely, yesterday is already the date that you want? Why can’t you simply pass that to the query?

Leave a comment