Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3950876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:39:48+00:00 2026-05-20T01:39:48+00:00

Using Jinja2, how do I format a date field? I know in Python I

  • 0

Using Jinja2, how do I format a date field? I know in Python I can simply do this:

print(car.date_of_manufacture.strftime('%Y-%m-%d'))

But how do I format the date in Jinja2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:39:49+00:00Added an answer on May 20, 2026 at 1:39 am

    There are two ways to do it. The direct approach would be to simply call (and print) the strftime() method in your template, for example

    {{ car.date_of_manufacture.strftime('%Y-%m-%d') }}
    

    Another, sightly better approach would be to define your own filter, e.g.:

    from flask import Flask
    import babel
    
    app = Flask(__name__)
    
    @app.template_filter()
    def format_datetime(value, format='medium'):
        if format == 'full':
            format="EEEE, d. MMMM y 'at' HH:mm"
        elif format == 'medium':
            format="EE dd.MM.y HH:mm"
        return babel.dates.format_datetime(value, format)
        
    

    (This filter is based on babel for reasons regarding i18n, but you can use strftime too). The advantage of the filter is, that you can write

    {{ car.date_of_manufacture|format_datetime }}
    {{ car.date_of_manufacture|format_datetime('full') }}
    

    which looks nicer and is more maintainable. Another common filter is also the "timedelta" filter, which evaluates to something like "written 8 minutes ago". You can use babel.dates.format_timedelta for that, and register it as filter similar to the datetime example given here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
I am using Jinja2 to generate HTML files which are typically very huge in
I have started using Jinja2 as my templating engine on Google App Engine (in
I'm running the micro framework Bottle on Google App Engine. I'm using Jinja2 for
The code below is a sample form I'm using to learn jinja2. As written,
My application is running on App Engine and is implemented using Werkzeug and Jinja2
I use jinja2 for my template engine in python. i would like to join
I am using the Flask micro-framework which is based on Werkzeug, which uses Python.
Using SVN you can right click a folder TEST and add it to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.