Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

356
Views
Display Django time variable as full hours, minutes am/pm

I want to use a time variable instead of a CharField for a model, which displays multiple saved times. My issue is it displays as "9 am" instead of "9:00 am", and "noon" instead of "12:00 pm". Can anyone help? Thanks in advance.

Relevant code below-

models.py

class Post(models.Model):
time=models.TimeField()
free=models.CharField(max_length=50, default="")
player1=models.CharField(max_length=50, default="Player 1")
player2=models.CharField(max_length=50, default="Player 2")
player3=models.CharField(max_length=50, default="Player 3")
player4=models.CharField(max_length=50, default="Player 4")

def __str__(self):
    return self.time

HTML

 <h7>{{post.time}} &nbsp; &nbsp; <a href="{% url 'update0' post.id %}"  class="btn-sm btn-success" >Update</a></h7>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can try using built in date template tag.

{{ post.time|date:'H:i A' }}
over 4 years ago · Santiago Trujillo Report

0

You can achieve this by just using the built-in template datetime format like so:

{{ post.time|date:"h:i A" }}

This will display the datetime as: 09:00 AM. You can read more about this in the Django docs.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!