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 4048900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:52:36+00:00 2026-05-20T13:52:36+00:00

For example, if I have an array of datetime.date objects, I would like to

  • 0

For example, if I have an array of datetime.date objects, I would like to apply a date format filter to each of its elements, while still making use of the default string representation of the array.

Given a date array that looks like:

[datetime.date(2011, 2, 28), datetime.date(2011, 3, 1), datetime.date(2011, 3, 2)]

Assuming that I already passed it to the template’s context, I’d like to do this in the template:

<script>
    // ...
    var dates = {{ my_date_array|date:'b d, Y' }};
    // ...
</script>

so it produces:

    var dates = ['Feb 28, 2011', 'Mar 1, 2011', 'Mar 2, 2011'];

..instead of having to loop through the elements of the array.

Is this possible by default, without creating a custom filter?

  • 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-20T13:52:37+00:00Added an answer on May 20, 2026 at 1:52 pm

    Looking at the source, I’d say that’s not possible using the default date filter.

    You will have to either use a loop in your template, or create a custom filter that accepts a list of date objects.

    Update:

    It should be relatively easy to create your own filter by making use of the existing one. For example:

    from django.template.defaultfilters import date
    from django import template
    register = template.Library()
    
    # Only mildly tested. Use with caution.
    def datelist(values, arg=None):
        try:
            outstr = "', '".join([date(v, arg) for v in values])
        except TypeError: # non-iterable?
            outstr = date(values, arg)
        return "['%s']" % outstr
    register.filter('datelist', datelist)
    

    If you don’t like that approach for determining iterable objects, you could also use:

    # requires Python >=2.4
    from collections import Iterable
    
    if isinstance(values, Iterable):
        # ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example i have an array like this: $test= array(0 => 412, 1 =>
Here's the problem. I ,for example,have a string 2500.Its converted from byte array into
for example: I have created one javascript property array model with some properties like
For example I have an array with about 10 elements in it. std::deque<int> d;
I want to enumerate all possible combinations of elements array. For example: I have
Let's say I have an array of objects with different specific generic types like
How to compare 2 arrays with each other? For example i have array(a, b,
For example, I have array // In $arr = [0, 1, 2, 4, 5];
I have the array: example = ['foo', 'bar', 'quux'] I want to iterate over
I have an array of strings(as shown in example). I just wish to find

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.