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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:02:30+00:00 2026-05-10T15:02:30+00:00

Given a datetime.time value in Python, is there a standard way to add an

  • 0

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example?

These obvious ideas don’t work:

>>> datetime.time(11, 34, 59) + 3 TypeError: unsupported operand type(s) for +: 'datetime.time' and 'int' >>> datetime.time(11, 34, 59) + datetime.timedelta(0, 3) TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta' >>> datetime.time(11, 34, 59) + datetime.time(0, 0, 3) TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.time' 

In the end I have written functions like this:

def add_secs_to_time(timeval, secs_to_add):     secs = timeval.hour * 3600 + timeval.minute * 60 + timeval.second     secs += secs_to_add     return datetime.time(secs // 3600, (secs % 3600) // 60, secs % 60) 

I can’t help thinking that I’m missing an easier way to do this though.

Related

  • python time + timedelta equivalent
  • 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. 2026-05-10T15:02:31+00:00Added an answer on May 10, 2026 at 3:02 pm

    You can use full datetime variables with timedelta, and by providing a dummy date then using time to just get the time value.

    For example:

    import datetime a = datetime.datetime(100,1,1,11,34,59) b = a + datetime.timedelta(0,3) # days, seconds, then other fields. print(a.time()) print(b.time()) 

    results in the two values, three seconds apart:

    11:34:59 11:35:02 

    You could also opt for the more readable

    b = a + datetime.timedelta(seconds=3) 

    if you’re so inclined.


    If you’re after a function that can do this, you can look into using addSecs below:

    import datetime  def addSecs(tm, secs):     fulldate = datetime.datetime(100, 1, 1, tm.hour, tm.minute, tm.second)     fulldate = fulldate + datetime.timedelta(seconds=secs)     return fulldate.time()  a = datetime.datetime.now().time() b = addSecs(a, 300) print(a) print(b) 

    This outputs:

     09:11:55.775695  09:16:55 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Aside from collaborating with a 3rd party ASP-style vendor (like… May 11, 2026 at 2:04 pm
  • added an answer What do you mean by 'runtime symbol lookup'? Do you… May 11, 2026 at 2:04 pm
  • added an answer Look at Dan Olson's dissasembly, it looks like a short… May 11, 2026 at 2:04 pm

Related Questions

Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a date/time as an array of (year, month, day, hour, minute, second), how
Given a DateTime representing a person's birthday, how do I calculate their age in
In MS SQL 2000 and 2005, given a datetime such as '2008-09-25 12:34:56' what
I am somewhat new to transactional databases and have come across an issue I
I've googled around and searched the MYSQL docs ad nauseam and couldn't find a
I've seen different questions on SO about not being able to use parameterless constructors
Both System.Timers.Timer and System.Threading.Timer fire at intervals that are considerable different from the requested

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.