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

  • SEARCH
  • Home
  • 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 7651467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:30:53+00:00 2026-05-31T11:30:53+00:00

I need to find out how many days in between two date ranges. The

  • 0

I need to find out how many days in between two date ranges. The problem I am having is that I am pulling the dates when I pass the form and they are coming back as unicode objects, therefor this (below) won’t work.

start = data.get('start_date')
mat = data.get('maturity_date')
delta = start - mat
term_string += "%s" % (delta,)

When I try a print statement, the date output is March 01, 2012 because the widget on my form converts it to that format. I am wondering if there is a way to take these unicode strings and convert them back into a date format so I can use delta to get the # of days.

Edit
I am passing the information through print_form() which sends the data from the form to my function that allows me to fill a pdf with the information.

print_form from lib/tools.py

def print_form(client=None, data=None, investment_form=None, type="gic_application", plan=None, investment=None):
...
    if data:
        term_string = ''
    total_days = 0
    if investment:
        if investment.term_years:
            term_string += "%s" % (investment.term_years,)
            fdf += fdf_val_str("term_years", investment.term_years)
            fdf += fdf_val_str("Term", "Years")
        if investment.term_months:
            start = data.get('start_date')
            mat = data.get('maturity_date')
            delta = start - mat
            term_string += "%s" % (delta,)
            fdf += fdf_val_str("Term", "Days")
        if investment.term_days:
            total_days += investment.term_days
            term_string += "%s" % (total_days,)
            fdf += fdf_val_str("Term", "Days")
...
response = HttpResponse(fdf.encode("ISO-8859-1"), mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=form.xfdf'#% download_filename# % (statement_date, "statements")
return response

And these are the date fields from my forms.py

start_date = forms.DateField(widget=DateInput, required=False)
maturity_date = forms.DateField(widget=DateInput, required=False)
  • 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-31T11:30:54+00:00Added an answer on May 31, 2026 at 11:30 am

    See Alasdair’s comment above; however, for the sake of completion:

    Even if you are not using django’s form processing, let’s say the data were coming in from a text file, or something like that and you just want to parse the data directly without using the Form api, you can always convert datetime strings in python by using the tools in the datetime module, these are: strftime and strptime. The notation for conversion is fairly standard across several language implementations.

    I worked on something not too long ago where the text file was extremelly large, but all the data was predictable and guaranteed to be error free. To insert into postgres would have added a significant amount of time using the form’s api, so I was parsing directly using python, and saved several hours (these were very complex inserts and several million line items)

    Regarding strftime and strptime, the docs are found here: http://docs.python.org/library/datetime.html#strftime-strptime-behavior

    All that said, I think Alasdair’s comment will fix your specific problem.

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

Sidebar

Related Questions

I need help on how to find out how many days it has been
I need to find out how many times the number greater than or less
I need to find out how many even values are contained in a binary
I have a bunch of log files. I need to find out how many
I need to find out how many characters were removed from the start of
Given an area of specific size I need to find out how many pavement
I need to find out how many pages of memory a process allocates? Each
I need to find out how many th have the class 'ui-tableFilter-filtered'; I tried
I have an integer and need to find out how many digits are in
I have a DataSet where I need to find out how many rows has

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.