473,473 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

finding time difference

20 New Member
This is probably a very basic question, how do I find out the difference between two system time.

I tried
x1 = t1.clock
x2 = t2.clock
x2 - x1
doesn't seem to give me the difference.

Also trying this way ,

x = time.localtime()
y = time.localtime()

tmp_time = str(x[3])+ ':' +str(x[4]) + ':' + str(x[5])

gives me output as 11:34:5 but I cannot find the difference between these two as it gives me the following error

y-x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'time.struct_time' and 'time.struct_time'

Any tips ??

-V
Mar 8 '07 #1
1 7838
bartonc
6,596 Recognized Expert Expert
This is probably a very basic question, how do I find out the difference between two system time.

I tried
x1 = t1.clock
x2 = t2.clock
x2 - x1
doesn't seem to give me the difference.

Also trying this way ,

x = time.localtime()
y = time.localtime()

tmp_time = str(x[3])+ ':' +str(x[4]) + ':' + str(x[5])

gives me output as 11:34:5 but I cannot find the difference between these two as it gives me the following error

y-x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'time.struct_time' and 'time.struct_time'

Any tips ??

-V
datetime objects can be added and subtracted. The result is a timedelta object.
In version 2.4.4 of the Python Library Reference it's in section 6.10.
datetime2 = datetime1 + timedelta (1)
datetime2 = datetime1 - timedelta (2)
timedelta = datetime1 - datetime2 (3)

(1)
datetime2 is a duration of timedelta removed from datetime1, moving forward in time if timedelta.days > 0, or backward if timedelta.days < 0. The result has the same tzinfo member as the input datetime, and datetime2 - datetime1 == timedelta after. OverflowError is raised if datetime2.year would be smaller than MINYEAR or larger than MAXYEAR. Note that no time zone adjustments are done even if the input is an aware object.


(2)
Computes the datetime2 such that datetime2 + timedelta == datetime1. As for addition, the result has the same tzinfo member as the input datetime, and no time zone adjustments are done even if the input is aware. This isn't quite equivalent to datetime1 + (-timedelta), because -timedelta in isolation can overflow in cases where datetime1 - timedelta does not.

(3)
Subtraction of a datetime from a datetime is defined only if both operands are naive, or if both are aware. If one is aware and the other is naive, TypeError is raised.
If both are naive, or both are aware and have the same tzinfo member, the tzinfo members are ignored, and the result is a timedelta object t such that datetime2 + t == datetime1. No time zone adjustments are done in this case.

If both are aware and have different tzinfo members, a-b acts as if a and b were first converted to naive UTC datetimes first. The result is (a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None) - b.utcoffset()) except that the implementation never overflows.
Mar 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
2
by: Robizzle | last post by:
Sorry, I must be blind but I can't seem to find it anywhere. What function will return the time a file was created? I see filemtime(...) returns the time that file was last Modified and...
5
by: Mike | last post by:
Hi I've written a module to find the first occurrence of a record in a query (that is my forms datasource) that matches four specified criteria. No matter what I try it doesn't seem to find ...
15
by: Benjamin Rutt | last post by:
Are there any C tools that can find redundant #includes in a project, so as to shorten compile time? Of course, eliminating single #includes by hand and determining if the recompile fails is one...
11
by: srkkreddy | last post by:
Hi, I have written a large program which makes multiple calls to number of functions (also written by me) of the program. Now, I want to know the collective time taken by all the calls to a...
4
by: David Warner | last post by:
Greetings! In looking into some C coding, I am looking for the C function that will search for multiple occurances of a same character in a string. For Instance: char str = "We the people...
22
by: Annajiat | last post by:
Hi, a) int grid; Which of the following is faster? 1. memset(grid,0,1010*1010); 2. memset(grid,0,sizeof(grid)); b) Is there any faster alternative to initializing memory? c) What is the...
17
by: abhimanyu.v | last post by:
Hi Guys, I have one doubt. The test program is given below. It uses two way of finding out the offset of a variable in structure. I executed the program and found the same result. My question...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.