S7H
S7H

Reputation: 1635

In Django template how to separate Date and time from DateTimeField?

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 ?

Upvotes: 2

Views: 3661

Answers (1)

Hedde van der Heide
Hedde van der Heide

Reputation: 22459

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

all options explained: documentation

Upvotes: 18

Related Questions