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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:49:00+00:00 2026-06-01T11:49:00+00:00

Hi I am writing a program that is dependent on time and observing some

  • 0

Hi I am writing a program that is dependent on time and observing some curious behavior with datetime objects I cannot quite figure out. The code I am working with / am having trouble with is…

now = datetime.now()
time_changed_state = some datettime object previously initialized
time_delay = some integer
time_arrival = time_changed_state + timedelta(minutes=time_delay)

if now < time_arrival:
   do something
elif now >= time_arrival:
   do something different

I have been working with test cases in order ot make sure the code behaves the way I would like it to but it doesn’t seem to.

I discovered the odd behavior when the time_delay = 0, and I know for a fact that now would be >= time_arrival since time_changed_state was a datetime object initilizated before this function call and now was initialized within the function. However, the “do something” code is being executed rather than the “do something different code”.

Thanks so much!

  • 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-01T11:49:02+00:00Added an answer on June 1, 2026 at 11:49 am

    I’ve edited your code, is this what you are expecting?

    from datetime import datetime
    from datetime import timedelta
    
    now = datetime.now()
    time_changed_state = now - timedelta(hours=2)
    time_delay = 0
    time_arrival = time_changed_state + timedelta(minutes=time_delay)
    
    if now < time_arrival:
       print 'something'
    elif now >= time_arrival:
       print 'something different'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I am writing a program that generates a single large table of information. The
I am writing a program that needs to run a java.jar server. I need
I am writing a program that uses prints a hex dump of its input.
I am writing a program that is cross platform. There are a few spots
I'm writing a program that needs to print off high resolution .tiff images. The
I am writing a program that convert TM-2 degree to lat/lon on Android, but
I'm writing a program that creates and edits directories and files in a file
I'm writing a program that uses regular expressions to make comparisons against the entire
A requirement for a program I am writing is that it must be able

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.