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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:06:22+00:00 2026-06-14T05:06:22+00:00

I have a datetime that I save to a file like this: time1 =

  • 0

I have a datetime that I save to a file like this:

time1 = datetime.datetime.now()
f.write(str(time1))

Now when I read it I realize time is a string. I’ve tried different ways to convert it but with no luck so far.

time = line[x:x+26]

How can I convert a string representation of a datetime back into a datetime object?

  • 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-14T05:06:23+00:00Added an answer on June 14, 2026 at 5:06 am

    First, you need to figure out the format of the date in your file and use the strptime method, e.g.

    # substitute your format
    # the one below is likely to be what's saved by str(datetime)
    previousTime = datetime.datetime.strptime(line[x:x+26], "%Y-%m-%d %H:%M:%S.%f") 
    

    (You’d better use dt.strftime(...) than str(dt) though)

    Then subtract the datetime objects to get a timedelta

    delta = datetime.datetime.now() - previousTime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this to save my file string m_strDate = DateTime.Now.ToString(MM/dd/yyyy); m_strDate =
I have a datetime field like that. <field name=rel_date type=date indexed=true stored=true default=NOW multiValued=false/>
I have heard that DateTime.Now is very expensive call (from here ) Is GETDATE()
I have a Python datetime object that I want to convert to unix time,
datetime.datetime.utcnow() Why does this datetime not have any timezone info given that it is
I have a table that has two datetime columns (one for start time and
This is C#/.NET 2.0. So I have string that contains the future contents of
I have a program that is saves information like a list of names, file
I have a datetime column in db that I want to transform into a
Suppose I have a datetime column in MySQL. How do I select all that

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.