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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:06:09+00:00 2026-06-12T03:06:09+00:00

Possible Duplicate: Converting string into datetime I am parsing an XML file that gives

  • 0

Possible Duplicate:
Converting string into datetime

I am parsing an XML file that gives me the time in the respective isoformat:

tc1 = 2012-09-28T16:41:12.9976565
tc2 = 2012-09-28T23:57:44.6636597

But it is being treated as a string when I retrieve this from the XML file.
I have two such time values and i need to do a diff between the two so as to find delta.
But since it is a string I can not directly do tc2-tc1. But since they are already in isoformat for datetime, how do i get python to recognize it as datetime?

thanks.

  • 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-12T03:06:10+00:00Added an answer on June 12, 2026 at 3:06 am

    Use the datetime.strptime method:

    import datetime
    datetime.datetime.strptime(your_string, "%Y-%m-%dT%H:%M:%S.%f")
    

    The link provided presents the different format directives. Note that the microseconds are limited to the range [0,999999], meaning that a ValueError will be raised with your example (you’re using 1/10us): you need to truncate your string to drop the final character.

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

Sidebar

Related Questions

Possible Duplicate: Converting a string that represents a list, into an actual list object.
Possible Duplicate: Converting string of 1s and 0s into binary value I would like
Possible Duplicate: Parse C# string to DateTime I am facing a problem while converting
Possible Duplicate: converting a string into a double What is the optimal way to
Possible Duplicate: Converting an uint64 into a (full)hex string, C++ I am trying to
Possible Duplicate: Alternative to itoa() for converting integer to string C++? How to convert
Possible Duplicate: Converting ereg expressions to preg I am totally new to parsing a
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
Possible Duplicate: Converting string to MySQL timestamp format in php Given a date in
Possible Duplicate: Converting string in C# I want to camelize a string, for example:

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.