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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:19:12+00:00 2026-05-11T06:19:12+00:00

Following on from my previous question, Python time to age , I have now

  • 0

Following on from my previous question, Python time to age, I have now come across a problem regarding the timezone, and it turns out that it’s not always going to be ‘+0200’. So when strptime tries to parse it as such, it throws up an exception.

I thought about just chopping off the +0200 with [:-6] or whatever, but is there a real way to do this with strptime?

I am using Python 2.5.2 if it matters.

>>> from datetime import datetime >>> fmt = '%a, %d %b %Y %H:%M:%S +0200' >>> datetime.strptime('Tue, 22 Jul 2008 08:17:41 +0200', fmt) datetime.datetime(2008, 7, 22, 8, 17, 41) >>> datetime.strptime('Tue, 22 Jul 2008 08:17:41 +0300', fmt) Traceback (most recent call last):   File '<stdin>', line 1, in <module>   File '/usr/lib/python2.5/_strptime.py', line 330, in strptime     (data_string, format)) ValueError: time data did not match format:  data=Tue, 22 Jul 2008 08:17:41 +0300  fmt=%a, %d %b %Y %H:%M:%S +0200 
  • 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-11T06:19:12+00:00Added an answer on May 11, 2026 at 6:19 am

    New in version 2.6.

    For a naive object, the %z and %Z format codes are replaced by empty strings.

    It looks like this is implemented only in >= 2.6, and I think you have to manually parse it.

    I can’t see another solution than to remove the time zone data:

    from datetime import timedelta,datetime try:     offset = int('Tue, 22 Jul 2008 08:17:41 +0300'[-5:]) except:     print 'Error'  delta = timedelta(hours = offset / 100)  fmt = '%a, %d %b %Y %H:%M:%S' time = datetime.strptime('Tue, 22 Jul 2008 08:17:41 +0200'[:-6], fmt) time -= delta 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • 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 You can also do SELECT * FROM table WHERE datetime… May 11, 2026 at 2:27 pm
  • added an answer Either Don't call the datagrid to display in new window.… May 11, 2026 at 2:27 pm
  • added an answer This is not really programming related. However, I would look… May 11, 2026 at 2:27 pm

Related Questions

Following up on my previous question on the enduring properties of a book on
Following on from my previous question , is it possible to make a Python
Following on from my previous question [link text][1] , I have a new problem.
Hello again ladies and gents! OK, following on from my other question on ASP.NET

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.