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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:50:29+00:00 2026-06-07T13:50:29+00:00

My timezone is UTC+5. So when i do datetime.datetime.now() it gives: 2012-07-14 06:11:47.318000 #note

  • 0

My timezone is UTC+5.

So when i do datetime.datetime.now() it gives:

2012-07-14 06:11:47.318000
#note its 6AM

I wanted to subtract 5 hours from it so that it becomes equal to datetime.datetime.utcnow() so i did:

import time
from datetime import datetime, timedelta
dt = datetime.now() - timedelta(hours=time.timezone/60/60)
print dt
#gives 2012-07-14 11:11:47.319000

"""
Here 11 is not the PM its AM i double check it by doing
print dt.strftime('%H:%M:%S %p')
#gives 11:11:47 AM
"""

You see instead of subtracting 5 hours it adds 5 hours into datetime??
Am I doing something wrong here?

  • 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-06-07T13:50:36+00:00Added an answer on June 7, 2026 at 1:50 pm

    You’re creating a negative timedelta. The value of time.timezone is negative:

    >>> import time
    >>> time.timezone
    -36000
    

    Here, I’m in UTC + 10, so your code becomes:

    >>> from datetime import timedelta
    >>> print timedelta(hours=time.timezone/60/60)
    -1 day, 14:00:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The output of datetime.datetime.now() outputs in my native timezone of UTC-8. I'd like to
I need to calculate the offset, in hours, of a given timezone from UTC
I currently have a list of DateTimes stored as the timezone's UTC datetime. When
I have a requirement where I have to convert timezone from UTC to a
I have a DateTime d and a string tz that is a valid ActiveSupport::TimeZone
I am trying to subtract one date value from the value of datetime.datetime.today() to
I have an ASP.NET MVC app that stores all SQL DateTime in UTC, so
I store time in UTC timezone in MySQL DATETIME field. I want to convert
Is there a simple way to remove the timezone from a pytz datetime object?
I need to force any time related operations to GMT/UTC, regardless the timezone set

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.