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

The Archive Base Latest Questions

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

at the start and end of my program, I have from time import strftime

  • 0

at the start and end of my program, I have

from time import strftime
print int(strftime("%Y-%m-%d %H:%M:%S")



Y1=int(strftime("%Y"))
m1=int(strftime("%m"))
d1=int(strftime("%d"))
H1=int(strftime("%H"))
M1=int(strftime("%M"))
S1=int(strftime("%S"))


Y2=int(strftime("%Y"))
m2=int(strftime("%m"))
d2=int(strftime("%d"))
H2=int(strftime("%H"))
M2=int(strftime("%M"))
S2=int(strftime("%S"))

print "Difference is:"+str(Y2-Y1)+":"+str(m2-m1)+":"+str(d2-d1)\
          +" "+str(H2-H1)+":"+str(M2-M1)+":"+str(S2-S1)

But when I tried to get the difference, I get syntax errors…. I am doing a few things wrong, but I’m not sure what is going on…

Basically, I just want to store a time in a variable at the start of my program, then store a 2nd time in a second variable near the end, then at the last bit of the program, compute the difference and display it. I am not trying to time a function speed. I am trying to log how long it took for a user to progress through some menus. What is the best 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-16T04:27:54+00:00Added an answer on May 16, 2026 at 4:27 am

    The datetime module will do all the work for you:

    >>> import datetime
    >>> a = datetime.datetime.now()
    >>> # ...wait a while...
    >>> b = datetime.datetime.now()
    >>> print(b-a)
    0:03:43.984000
    

    If you don’t want to display the microseconds, just use (as gnibbler suggested):

    >>> a = datetime.datetime.now().replace(microsecond=0)
    >>> b = datetime.datetime.now().replace(microsecond=0)
    >>> print(b-a)
    0:03:43
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have one application which get the start and end time from the user
I have a start and end time in a timestamp format. I want to
I received the following script from a fellow programmer: from time import * start
In my perl program, I am calculating warranty start date from warranty end date
Hey, I am trying to get a service to start my program but it
I have a program that get sensors data from a Como database and put
I have a dataframe that looks like this: person n start end 1 sam
I am coding in php, attempting to get the start\end dates and times for
I am using start and end dates over multiple forms, but these properties are
if you know the start and end positions in string from where to begin

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.