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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:14:49+00:00 2026-05-13T23:14:49+00:00

t1 = datetime.time(12, 10, 0, tzinfo=GMT1()) # 12:10 t2 = datetime.time(13, 13, 0, tzinfo=GMT1())

  • 0
t1 = datetime.time(12, 10, 0, tzinfo=GMT1()) # 12:10
t2 = datetime.time(13, 13, 0, tzinfo=GMT1()) #13:13
t3 = datetime.time(23, 55, 0, tzinfo=GMT1()) #23:55 
t4 =  datetime.time(01, 10, 0, tzinfo=GMT1()) #01:10

I need the minute interval between between two times. For instance a non working one:

def minute_interval(start,end):
     return end - start

minute_interval(t1,t2) #should give 63 mins.

Also if the end time is smaller than start, it should do the calculation by understaing the end is from the next days time. ie:

minute_interval(t3,t4) #should give 75 mins.

How can this be achieved ? I need to rewrite the minute_interval function for this aim.

  • 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-13T23:14:50+00:00Added an answer on May 13, 2026 at 11:14 pm

    Assuming time are in same timezone and no DST

    import datetime
    
    def minute_interval(start, end):
         reverse = False
         if start > end:
              start, end = end, start
              reverse = True
    
         delta = (end.hour - start.hour)*60 + end.minute - start.minute + (end.second - start.second)/60.0
         if reverse:
              delta = 24*60 - delta
         return delta
    
    t1 = datetime.time(12, 10, 0) # 12:10
    t2 = datetime.time(13, 13, 0) #13:13
    t3 = datetime.time(23, 55, 0) #23:55 
    t4 = end = datetime.time(01, 10, 0) #01:10
    
    print minute_interval(t1, t2)
    print minute_interval(t3, t4)
    

    output:

    63
    75
    

    otherwise you are better of using datetime.datetime, which supports subtraction and gives datetime.timedelta, for timezone you can use pytz library.

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

Sidebar

Related Questions

I use JodaTime library for time operations. I have two dates: Date One: DateTime
I need to convert a Joda-Time DateTime into a String, in the following format:
Suppose I have list of time interval like a = [datetime.time(0,0),datetime.time(8,0)] Now I Have
I'm trying to compare two times using the Python datetime module, but I can't
I have the following script defining a tzinfo object: import time from datetime import
class order { Guid employeeId; DateTime time; } I need to filter a list
I have two structs like so: public struct KeyLog { Keys key; DateTime time;
Python 2.6: import pytz import time import datetime time.mktime(datetime.datetime(1990, 1, 1, tzinfo=pytz.utc).timetuple()) Result: 631148400.0
My database currently uses datetime for time, and does a number of selects against
This line of code: DateTime dt = DateTime.ParseExact(time, hh:mm, CultureInfo.InvariantCulture); parses a time value

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.