Solved

subtracting time

Posted on 2004-08-31
3
723 Views
Last Modified: 2008-03-17
I have time that i read from a file.
The time is of the format hh:mm:ssssss
now i have to subtract the one time from other.
is there a special class for doing it or any special way of doing it ?

thanks.

iCe b
0
Comment
Question by:iceb
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 450 total points
ID: 11947601
That depends on your implementation. By example in Visual C++ you have the CTime and CTimeSpan class.
A portable way is to use the struct tm;

struct tm aTime;
aTime.tm_hour = 5;
aTime.tm_min = 15;
aTime.tm_sec = 43;
// etcetera

now to convert to a unique value use mktime()

time_t time;   // one unique integer to express time, know as Unix-Time
time = mktime(aTime);

if you have another time_t value, you can substract one for the other, result is expresed in seconds

Read more at:
http://msdn.microsoft.com/library/en-us/vclib/html/_crt_time_management.asp
0
 
LVL 3

Assisted Solution

by:kumvjuec
kumvjuec earned 50 total points
ID: 11965861
If the time is all you have, then the best way is to convert both the times into seconds and then convert them back again.
If you are using c++ then use atol to convert from string to long. This is required because if would be easier to read directly the line from the file as string.

What language are you using btw??
0
 
LVL 1

Author Comment

by:iceb
ID: 12002601
i am using vc++ 6.0.
program is scre*ed up.
please gimme some time to respond.

thx for the replies.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now