1,105,592 Community Members

Problem calculating days between 2 dates

Member Avatar
Dave Sinkula
long time no c
4,852 posts since Apr 2004
Reputation Points: 2,398 [?]
Q&As Helped to Solve: 340 [?]
Skill Endorsements: 69 [?]
Team Colleague
 
0
 

>>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?

Member Avatar
Ancient Dragon
Achieved Level 70
27,680 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,041 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

>>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":icon_eek: What a waste of cpu time.

Member Avatar
Dave Sinkula
long time no c
4,852 posts since Apr 2004
Reputation Points: 2,398 [?]
Q&As Helped to Solve: 340 [?]
Skill Endorsements: 69 [?]
Team Colleague
 
0
 

>>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":icon_eek: 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?

Member Avatar
Sturm
Veteran Poster
1,067 posts since Jan 2007
Reputation Points: 270 [?]
Q&As Helped to Solve: 31 [?]
Skill Endorsements: 0 [?]
 
0
 

time_t is only guarenteed to be an integral type on POSIX systems.

Member Avatar
Ancient Dragon
Achieved Level 70
27,680 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,041 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
-1
 

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/clibrary/ctime/time_t/

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article