![]() |
algorithm: help needed in difference of dates
lets say i have the date as year, month and day in three variables:-
y1, m1 and d1 and another date in:- y2, m2 and d2 is there any good algorithm to find the difference in the number of days between these two dates. i would be thankful if anyone can provide me a link to any such alogrithm or post a description here. example data:- 14th June 1983: y1=1983, m1=06, d1=14 15th April 2006: y2=2006, m2=04, d2=15 |
I'm not aware of any such calculator offhand, but it wouldn't be hard to whip one up.
30 days hath September, April, June, and November All the rest have 31 Except February clear, which has 28 or 29 (each leap year). In the gregorian calendar, a leap year is every year divisible by 4. But a year divisible by 100 is not a leap year, unless it is also divisible by 400. This should be reasonably accurate for the next 8000 years or so..... when other effects such as the earth's orbit around the sun wobbling a bit will introduce a slight (unfortunately, not totally predictable) error. |
One way is to convert both dates into a Julian date, which is an integer number of days from a certain date in the past. Here is one method in C for doing so. Yo can then subtract one value from the other to find the number of days between the two dates.
|
Consider using strptime - which is pretty flexible. Most compilers now support it. Older Windows compilers don't. Most calendric work uses strptime to convert dates to seconds in the epoch, which is the basis for time and date calculations in C.
:
#include <time.h> |
| All times are GMT -5. The time now is 8:03 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC