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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:46:51+00:00 2026-05-23T13:46:51+00:00

This question is similar to this question about subtracting dates with Python , but

  • 0

This question is similar to this question about subtracting dates with Python, but not identical. I’m not dealing with strings, I have to figure out the difference between two epoch time stamps and produce the difference in a human readable format.

For instance:

32 Seconds
17 Minutes
22.3 Hours
1.25 Days
3.5 Weeks
2 Months
4.25 Years

Alternately, I’d like to express the difference like this:

4 years, 6 months, 3 weeks, 4 days, 6 hours 21 minutes and 15 seconds

I don’t think I can use strptime, since I’m working with the difference of two epoch dates. I could write something to do this, but I’m quite sure that there’s something already written that I could use.

What module would be appropriate? Am I just missing something in time? My journey into Python is just really beginning, if this is indeed a duplicate it’s because I failed to figure out what to search for.

Addendum

For accuracy, I really care most about the current year’s calendar.

  • 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-23T13:46:51+00:00Added an answer on May 23, 2026 at 1:46 pm

    You can use the wonderful dateutil module and its relativedelta class:

    import datetime
    import dateutil.relativedelta
    
    dt1 = datetime.datetime.fromtimestamp(123456789) # 1973-11-29 22:33:09
    dt2 = datetime.datetime.fromtimestamp(234567890) # 1977-06-07 23:44:50
    rd = dateutil.relativedelta.relativedelta (dt2, dt1)
    
    print "%d years, %d months, %d days, %d hours, %d minutes and %d seconds" % (rd.years, rd.months, rd.days, rd.hours, rd.minutes, rd.seconds)
    # 3 years, 6 months, 9 days, 1 hours, 11 minutes and 41 seconds
    

    It doesn’t count weeks, but that shouldn’t be too hard to add.

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

Sidebar

Related Questions

I asked a similar question about this previously, but I did not specify that
This question is about a whole class of similar problems, but I'll ask it
This is related to a similar question about BIND, but in this case I'm
I am posting this question after reading other similar questions about my problem but
This question is similar to this one about animation queues , but the answers
This question is similar to this one , but not a duplicate because I'm
This question is similar to, but not the same as, Logcat errors when running
I noticed some similar questions about this problem when I typed the title, but
My question is very similar to this question but a bit more specific. My
I understand that this question is similar to others asking about Java Properties, and

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.