2

I want to print only the date on my Django template. This is my model.

class Comment(models.Model):
    name = models.ForeignKey(User)
    body = models.TextField()
    pub_date = models.DateTimeField(auto_now_add=True)
    article  = models.ForeignKey(Article)

Now to print both date and time on a template I can use {{object.pub_date}} to print. But I only want to print the date, not the time. Is there a way to do so in Django Templates ?

S7H
  • 1,421
  • 1
  • 22
  • 37
  • there are so many answer that you could find on stackoverflow please do some search before you ask question [answer](http://stackoverflow.com/questions/7737146/django-template-date-format) – Ben Hsieh Jun 12 '15 at 09:15

1 Answers1

16
{{ object.pub_date|date:"D d M Y" }} {{ object.pub_date|time:"H:i" }}

all options explained: documentation

Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100