0

From this answer

In my template i need to make 1255992517000 to an date-time. i tried {{note.created|date:"U"}} and 1255992517000|date:"U" but it didn't work. How to get it to work? From django docs one can see it should work, but how?

Community
  • 1
  • 1
Mihkel L.
  • 1,543
  • 1
  • 27
  • 42

2 Answers2

3

You are misunderstanding what the {{ value|date }} filter is capable of doing. It will not turn an integer into a date object, you must be passing it an existing date object.

You could write your own template filter to convert the value into a date first.

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
1

Applying the filter date:"U" is telling the template to display seconds since the Unix Epoch (January 1 1970 00:00:00 UTC).

If you want to display a readable date / time, try something like:

{{ note.created|date:"D d M Y" }}
Chris McKinnel
  • 14,694
  • 6
  • 64
  • 67
  • What do you get when you just use `{{ note.created }}`? – Chris McKinnel Feb 10 '13 at 19:26
  • 1
    Matthew (below) is right - the date filter expects an actual date object, you're passing it an integer. You need to change your `note.created` to be a date object, instead of just a timestamp, for the date filter to work. – Chris McKinnel Feb 11 '13 at 19:08