views:

44

answers:

2

Hi!

I am making a blog and store the publishing date of a blog post in the datastore. It looks like this:

post.date = datetime.datetime.now()

It now displays like: 2010-10-04 07:30:15.204352 But I want the datetime to be displayed differently. How (and where) can I set that how the date is displayed? I'd like to set the date format like in UNIX date function (like %Y/%m etc). I tried to add some parameters in my templates but that returned errors.

Thanks in advance!

-skazhy

+3  A: 

I think strftime is the method you're looking for.

From the link:

>>> d.strftime("%d/%m/%y")
'11/03/02'

If you pass in the result of the strftime in your 'template_values' or similar (the dictionary you use to pass parameters to the template) instead of the actual date it will be displayed instead.

sje397
+1  A: 

You can use .strftime() on a datetime object to do the formatting. See the relevant python documentation for details.

Ivo van der Wijk