943,614 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3514
  • C RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Jun 19th, 2009
0

Re: Problem calculating days between 2 dates

>>difftime()

I see absolutely no value in that function because all it does is subtract the two parameter values and return the result as a double. When time_t is an (unsigned)integer then the double return value is just plain inconvenient because it would have to be typecast back to time_t. So the program might as well just subtract the two time_t objects and be done with it.
Isn't that somewhat analogous to how the Y2K issue came about -- that rather than doing it the "right" way, the "easy" way was chosen?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 19th, 2009
0

Re: Problem calculating days between 2 dates

>>that rather than doing it the "right" way, the "easy" way was chosen?

You consider calling a function just to subtract two numbers is the "right way" What a waste of cpu time.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jun 19th, 2009
0

Re: Problem calculating days between 2 dates

>>that rather than doing it the "right" way, the "easy" way was chosen?

You consider calling a function just to subtract two numbers is the "right way" What a waste of cpu time.
You seem to consider that a time_t is a measure of seconds. This is not necessarily true. Is writing potentially buggy code a better use of CPU time?
Last edited by Dave Sinkula; Jun 19th, 2009 at 4:02 pm.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 19th, 2009
0

Re: Problem calculating days between 2 dates

time_t is only guarenteed to be an integral type on POSIX systems.
Last edited by Sturm; Jun 19th, 2009 at 4:14 pm.
Reputation Points: 343
Solved Threads: 24
Veteran Poster
Sturm is offline Offline
1,067 posts
since Jan 2007
Jun 22nd, 2009
-1

Re: Problem calculating days between 2 dates

Quote ...
Time type

Type capable of representing times and support arithmetical operations.

This type is returned by the time function and is used as parameter by some other functions of the <ctime> header.

It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms.
http://www.cplusplus.com/reference/c.../ctime/time_t/
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: 13th friday in c
Next Thread in C Forum Timeline: How to swap rows in single diemensional array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC