user8951490
user8951490

Reputation: 843

Display Django DateTime Field with strftime() method

I am trying to format the string of a DateTimeField contained in one of my models.

I am using this method inside the model:

def HTMLDisplayTime(self):
        time = self.time.date.strftime(%a %H:%M  %d/%m/%y)
        return time

Where "self.time" refers to the DateTimeField in question.

I have tried several variations, omitting some items, with and without .date preceding the .strftime method, and have imported both import datetime and from datetime import datetime.

Upvotes: 3

Views: 7380

Answers (1)

Ankita Gupta
Ankita Gupta

Reputation: 583

Try using quotes around the format argument in strftime() like:

time = self.time.strftime('%a %H:%M  %d/%m/%y')

Upvotes: 3

Related Questions