Suppose I have:
ds = datetime.datetime.now
dd = Entry.objects.get(pk=id).pub_date
How to compare 2 objects above? I want to get the time difference between them.
Please help me solve this problem. Thank you very much !
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I am assuming that
pub_dateis adjango.db.models.DateField, which means you can treat it as adatetime.dateobject.If you convert them to the same type (either
datetime.datetimeordatetime.date) and subtract one from the other, you will get an instance ofdatetime.timedelta.As you are using
datetime.datetime.now(), if yourpub_dateis simply a date rather than a datetime, you may as well useds = datetime.date.today()instead: