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 105k
  • Answers 105k
  • 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
  • Editorial Team
    Editorial Team added an answer I have installed 3.5 with VS.Net 2008 on Windows XP… May 11, 2026 at 8:42 pm
  • Editorial Team
    Editorial Team added an answer Well, it's kind of a hack, you could grab all… May 11, 2026 at 8:42 pm
  • Editorial Team
    Editorial Team added an answer I tested many ways till I came up to this… May 11, 2026 at 8:42 pm

Related Questions

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
I have a table that stores stock ticks in sql server 2008. It is

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.