Reputation:
I want to compare some date fields on the db and check if they are old or they were submited today , i got this code
{% if accounts.date.day == 13 %}
{{ accounts.name }}
{% endif %}
But i think this works on the day 13 of every motnh , and i dont want to only check if its day 13 i want to check if it wasnt today
I tried to do
{% if accounts.date.day < today %}
{{ accounts.name }}
{% endif %}
And in the views
today = datetime.datetime.now()
But it doesnt work either
Upvotes: 1
Views: 2990
Reputation: 114098
today = datetime.date.today()
if (today - accounts.date).days == 1:
print "%s is yesterday!"%accounts.date
maybe??
this assumes that accounts.date
is an instance of datetime.date
if {% if (today.date - accounts.date).days == 1 %}
might work in the template ... or you could create a filter (thats what I would do
def isYesterday(a_date):
return (datetime.date.today()-a_date).days == 1
then just do
{% if accounts.date | isYesterday %}
Upvotes: 2
Reputation: 818
if accounts.date is datetime try this
{% if accounts.date < today %}
{{ accounts.name }}
{% endif %}
Upvotes: 3