467,117 Members | 1,064 Online

# Calculating number of days between two dates.

 I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by the number of seconds in a day? - Clint Apr 25 '07 #1
• viewed: 20973
Share:
9 Replies
 clintonb wrote: I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by the number of seconds in a day? Sure, you could do that. Have you already tried? If not, why not? If yes, why do you ask? Did it work? V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Apr 25 '07 #2
 clintonb wrote: I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by the number of seconds in a day? Well, how many days are between 3pm Friday and 8am Saturday? 0? 1? Some fraction? You need to decide that first. Brian Apr 25 '07 #3
 clintonb wrote: I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by the number of seconds in a day? - Clint The key phrase is "Julian Date," which is a sort of free-running day counter that counts from a point way far back in prehistory, like 4713 BC. Astronomers use the Julian date, and it's easy to subtract two such dates to get the number of days. It's up to you how you want to count partial days. The only problem with Julian date is that the number is so huge. Especially back when computers had 16 bits -- or even 8 -- it required multiple words to store a JD. So several groups and companies chose to standardize on a date whose basis is not quite so far back. It's my understanding that Microsoft defined such a date. I guess that's what they use in their library of functions. If not, you can always use the true JD. Any good book on astronomy -- or, for that matter, many web sites -- will have pretty short algorithms for generating the number. Jack Jack Apr 26 '07 #4
 On Apr 26, 1:10 am, Jack Crenshaw
 On Apr 25, 6:37 pm, "Default User"
 On Apr 25, 5:42 pm, "Victor Bazarov"
 On Apr 25, 6:37 pm, "Default User"
 On May 22, 8:50 pm, clintonb
 On May 22, 6:37 pm, clintonb

### This discussion thread is closed

Replies have been disabled for this discussion.