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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:37:41+00:00 2026-05-22T02:37:41+00:00

I have 2 datetime values: ‘start’ and end’. I’d like to return a list

  • 0

I have 2 datetime values: ‘start’ and end’. I’d like to return a list of all the datetimes that fall exactly on the hour between the two (inclusive).

For example ‘start’ is 09:30 and ‘end’ is 14:00 (same day). The values I’d like returned are 10:00, 11:00, 12:00, 13:00, 14:00.

I guess what you would do is get the next whole hour after ‘start’, add it to a blank list, then create a loop that adds and hours, tests if it’s less than (or equal to) ‘end’ and append it to the list if true.

What I can’t figure out is how to get the nearest whole hour to the start datetime.

  • 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-22T02:37:42+00:00Added an answer on May 22, 2026 at 2:37 am

    The easiest would be to replace the minutes and seconds of the start time with zero and then add one hour.

    You will need a special case if the start time is exactly on the hour and you wish to include it

    eg

    >>> from datetime import datetime, timedelta
    >>> start_time = datetime.now()
    >>> start_time
    datetime.datetime(2011, 5, 18, 20, 38, 55, 546000)
    >>> first = start_time.replace(minute=0, second=0, microsecond=0)+timedelta(hours=1)
    >>> first
    datetime.datetime(2011, 5, 18, 21, 0)
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table that stores values with a point in time: CREATE TABLE
I have sql stored procedure which pass and return some values: CREATE PROCEDURE [dbo].[GetMoney]
I have an ssis package that imports a view from one database into different
I have a column with datetime datatype called 'updated_at' in a mysql table,where i
i have a usercontrol with two public properties public DateTime fromdate { get; set;
am using C#, VS 2005 and SQL 2000 I have date conversion problem my
I have a table var with some rows but only one column of type
Lets say I have object Tom which has class Person. Class Person String Name
So in my PHP code, I do timezone selection for the user, where I
I am trying to store HTML posted from a textarea into a database. I

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.