Russell,
I can give you a pointer to the number of days in a month for a given month
in a year taking leap years into account but I stress this is completely
untested and I'm fumbling trying to remember it from my pascal days (and
convert it at the same time). I guess using this you would need to get each
whole month and work out its number of days and then work out the remaining
days of any left over.
private bool isLeapYear(int year)
{
//needs some serious testing to make sure this works for every leap year
(esp y2k)
return (year % 4==0) &&((year % 100 !=0) | (year % 400 == 0));
}
private int DaysInAMonth(int month, int year)
{
int[] months = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31};
int x = months[month-1];
return (month == 2 && IsLeapYear(year))?++x:x;
}
Nev
"Russell" <ru************@hotmail.com> wrote in message
news:15*************************@posting.google.co m...
I have an assignment that I have to complete. I have to write a
windows app in C#. Here is the spec:
1/ Date Comparison
Build a program that will find the number of days between two dates.
You CANNOT use the inbuilt date functions or the DateTime Type. Your
program should work with any date between 1900 and 3000.
Here are your acceptance tests:
Days between 04/01/02 and 01/01/02 equals 3
Days between 01/05/1998 and 12/10/1977 equals 7506
Days between 01/01/2004 and 01/01/2003 equals 365
Days between 01/01/2002 and 01/01/2000 equals 731
I figure I could convert the dates to doubles and then subtract one
from the other but that wouldnt take leap years into account!!
Any ideas to get me started would be really appreciated!!
thanks
RuSs