Reputation: 2993
what should the following look like?
{% now "YmdHMS" %}
according to python...
>>> import datetime
>>> datetime.datetime.now().strftime("%Y%m%d%H%M%S")
'20140227121922'
but in my template, the result is...
2014022712Febth
How can I make this work properly?
Upvotes: 2
Views: 3307
Reputation: 79
complete date and time
{{ created_at|date:"Y-m-d H:i" }}
only time
{{ created_at|date:"H:i" }}
hours and minutes after the post created_at
{{ created_at|timesince }}
date and month
{{ created_at|date:"jS \o\f F"}}
Upvotes: 0
Reputation: 6009
{% now "YmdHis" %}
django templatetag filtering of datetime is different from python strftime()
Upvotes: 0
Reputation: 2514
Try:
{% now "YmdHis" %}
Here is a table with datetime format strings:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
You should take a look at those docs:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#now
https://docs.djangoproject.com/en/dev/topics/i18n/formatting/#format-localization
Upvotes: 4
Reputation: 2993
Just figured out that I'd make a function on the view to do this (because outside of the template the date string formats correctly). I'd still love to know why it doesn't work in the template...
Upvotes: 0