0

I'm having a little issue regarding showing months in words, instead of numbers. Right my blog is showing "13-03-2013", but I want it to be "13-March-2013"

Here are the things I did to get as far as I am now: I added the date in my models:

pub_date = models.DateTimeField("Gepubliceerd", auto_now_add=True)

When I call the variable pub_date in my blog template it shows in numbers(13-03-2013).

Is there an easy way to change the numbers to the actual month names? I've been thinking about creating a tuple with every month name in it, let it run a check which number of the month there is in pub_date, and according to that, use the right month from the tuple.

But for some reason I feel there has to be a easier way. But so far I haven't been successful finding another solution.

Hopefully some awsome people have experience with this!

Thx in advance!

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
Kevinvhengst
  • 1,672
  • 4
  • 27
  • 40

2 Answers2

8

You should use template filter date provided with Django. See the documentation on how to use it.

If you want to use this date format in exactly this one place just use

{{ pub_date|date:'d-F-Y' }

If that's the default format you want everywhere use the DATE_FORMAT and SHORT_DATE_FORMAT settings. Read the docs for more info.

dmedvinsky
  • 8,046
  • 3
  • 31
  • 25
  • Thanks! for some i failed badly in the research i did before. I can change the {{ pub_date|date:'d-m-Y' }} to {{ pub_date|date:'d-M-Y' }}. the capital M makes it show the word instead of the number! Thx for all the help anyway! ^^ – Kevinvhengst Mar 13 '13 at 07:04
1

so after some more research after this post (which i should've done before making this question) i came to the following:

{{ pub_date|date:'d-m-Y' }}

is how i call the date. Within that, you can play around with date format provided by Django itself. if you change the 'm' to a capital 'M', it will display the month in letters. But There are alot more possibility's explained over here:

Read here all about the Django date format

once again, sorry for asking a question to quickly

Kevinvhengst
  • 1,672
  • 4
  • 27
  • 40