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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:53:58+00:00 2026-05-16T02:53:58+00:00

What I am trying to do is to subtract 7 hours from a date.

  • 0

What I am trying to do is to subtract 7 hours from a date. I searched stack overflow and found the answer on how to do it here. I then went to go read the documentation on timedelta because I was unable to understand what that line in the accepted answer does, rewritten here for ease:

from datetime import datetime

dt = datetime.strptime( date, '%Y-%m-%d %H:%M' )
dt_plus_25 = dt + datetime.timedelta( 0, 2*60*60 + 30*60 )

Unfortunately, even after reading the documentation I still do not understand how that line works.

What is the timedelta line doing? How does it work?

Additionally, before I found this stackoverflow post, I was working with time.struct_time tuples. I had a variable tm:

tm  = time.strptime(...)

I was simply accessing the hour through tm.tm_hour and subtracting seven from it but this, for obvious reasons, does not work. This is why I am now trying to use datetime. tm now has the value

tm = datetime.strptime(...)

I’m assuming using datetime is the best way to subtract seven hours?

Note: subtracting seven hours because I want to go from UTC to US/Pacific timezone. Is there a built-in way to do this?

  • 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-16T02:53:59+00:00Added an answer on May 16, 2026 at 2:53 am

    What is the timedelta line doing? How does it work?

    It creates a timedelta object.

    There are two meanings of “time”.

    • “Point in Time” (i.e, date or datetime)

    • “Duration” or interval or “time delta”

    A time delta is an interval, a duration, a span of time. You provided 3 values.

    • 0 days.

    • 2*60*60 + 30*60 seconds.

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

Sidebar

Related Questions

Trying to think of a way to subtract 5 minutes from 2 hours. It
I am trying to subtract one date value from the value of datetime.datetime.today() to
I have two arrayLists and I am trying to subtract one arrayList from another.
I'm trying to subtract 1 (one) from a value with jQuery. I've managed to
I'm trying to subtract two values from each other using twos compliment. I have
I am trying to make an sql query to subtract two values from different
I am trying to subtract a second from time value in a time picker.
I have an R dataframe and I'm trying to subtract one column from another.
Hey guys i'm trying to figure out how to subtract one time from another
I am trying to subtract two values in my array the largest and the

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.