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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:41:01+00:00 2026-05-20T16:41:01+00:00

Given that I start with a string, like ‘3/6/2011’ which is month/day/year, and the

  • 0

Given that I start with a string, like '3/6/2011' which is month/day/year, and the current day is 3/13/2011 (7 days later), how can I find the number of years that have passed since that time (7/365 = 0.0191780821917808) in Python?

Note that I want to be able to handle any input date. Not any format though, you can assume the format above.

  • 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-20T16:41:01+00:00Added an answer on May 20, 2026 at 4:41 pm

    You can get the timedelta by subtracting two datetimes, which gives you a lot of cool ways to operate on the time difference.

    >>> import datetime
    >>> before = datetime.datetime.strptime('3/6/2011','%m/%d/%Y')
    >>> now = datetime.datetime.now()
    >>> type(now-before)
    <type 'datetime.timedelta'>
    >>> (now-before).days
    7
    >>> float((now-before).days)/365
    0.019178082191780823
    

    EDIT: Wow, who would’ve thought there was so much depth to this simple question. Take a look at the answer with the most votes on this question. Dealing with leap years is a “hard” problem. (Credit to @kriegar)

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

Sidebar

Related Questions

I would like to start a personal project that will give me a lot
Given that a function a_method has been defined like def a_method(arg1, arg2): pass Starting
I am trying to figure out a regular expression which matches any string that
Given a dictionary, I would like to get a new dictionary that is a
I was given this: Write a recursive program that, given a string with no
Greetings. Imagine you've been given a string (from somewhere you can't control). In that
Given that indexing is so important as your data set increases in size, can
Given that Chrome and Safari use webkit has anyone yet found anything that renders
Given that I only have one monitor, what's the best way to debug a
Given that Decimal.MaxValue = 79228162514264337593543950335m Why does the next line give me 7922816251426433759354395034M in

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.