Michael
Michael

Reputation: 2993

django template datetime filter displays month instead of minute

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

Answers (4)

Manoj Parmar
Manoj Parmar

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

Geo Jacob
Geo Jacob

Reputation: 6009

{% now "YmdHis" %}

django templatetag filtering of datetime is different from python strftime()

Upvotes: 0

Michael
Michael

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

Related Questions