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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:47:11+00:00 2026-06-04T10:47:11+00:00

I have a problem where I work a lot with time and time differences.

  • 0

I have a problem where I work a lot with time and time differences. So far I’ve solved this using many many if statements but these are error prone. In searching for a better solution and without reinventing the wheel, I came across time, date, and timedelta. But these seem too inflexible for me so I’m looking for ideas and tips on how to solve this problem using python’s built-in functions – if possible. Here’s the problem: Binning satellite data from swaths to regular grid involves lots of simple time calculations. If I have the date integer: 200702100700 I want to add and subtract hours and minutes from such a time format such that date – 18 would give me a new date that takes into account leap year and can go cross, year, month, day backwards and forwards. Here’s what I understand of python’s datetime package:

from datetime import timedelta, date, time
t1 = date(2007,01,01); t = time(12,0); t2 = datetime.combine(t1,t)
t3 = timedelta(hours=18); t4 = t2 - t3; t5 = t2 + t3
print t4
>>>datetime.timedelta(2006, 23401, 3001)

This time is not very useable in a script that will do thousands of calculations. My problem is that t4 has no year, month, or day objects, and 2006 seems to be treated as hours. It’s all very confusing. Is this possible in python/numpy/scipy? If so, can someone give me a tip?

  • 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-06-04T10:47:12+00:00Added an answer on June 4, 2026 at 10:47 am

    Gerrat got it right, use the datetime object.

    you can create the datetime object fully without creating date and time separately (or using datetime.strptime()).

    BUG ALERT Your code and some of the posted responses will inject a hard to see bug.

    // this works
    datetime(2007,01,01,12)
    // this breaks
    datetime(2007,01,09,12)
    

    In python, typing the “0” in “09” makes it an octal number (“09” is not valid) when using dates in in your code, avoid the leading zero.

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

Sidebar

Related Questions

I have a long standing problem: at work we're using mercurial as a DSCM,
I have this problem getting my newly created php project on Netbeans work on
I have a problem with IE. All other browsers work fine, but in IE
I have a similar problem to this guy: Importing/Exporting Project Preferences , but my
I spent a lot of time to solve this problem, yet still couldn't get
I've already put a lot of work into this problem and am really near
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I have a problem with getting my pager-function to work. For some reason it
I have one problem, I learn how work with socket and I write programm
I have a problem trying to edit. I work with Areas for better management

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.