Solved

subtracting time

Posted on 2004-08-31
3
720 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
Comment Utility
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
Comment Utility
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
Comment Utility
i am using vc++ 6.0.
program is scre*ed up.
please gimme some time to respond.

thx for the replies.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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