Re: number of days between two dates



technoboy2084 wrote:

> hello, sorry for my bad english
> i have some trouble making an exercise for school :(
>
> i need an algoritm that calculate the exactly number of days between
> two dates:
> for example:
> 01/01/1800 - 02/01/1800 --> 1 day
> 01/01/1800 - 01/01/1900 --> 36524 days
> 28/02/2004 - 01/03/2004 --> 2 days (2004 is a leap year !!!)
>
> someone can help me?
> thank you very much
>

Look for a Julian Date algorithm!

Or make your own: This is quite easy!

First you determine a starting year/date, I suggest 1600-03-01 since
that makes a lot of calculations much simpler.

Then you determine the number of full years between the zero date and
the current one, after first correcting the current date for the march
first staring point: If the month is jan or feb, then decrement the year
and add 9 to the month number, otherwise subtract 3 from the month. This
result in a month number in the 0 to 11 range.

At this point the day number calculation becomes simply

year -= 1600;
century = year / 100;
daynr = year * 365 + (year >> 2) - century + (century >> 2) +
DaysToMonth[month] + day;

The DaysToMonth[] table would of course contain the number of days
before the start of each month.

Terje

--
- <Terje.Mathisen@xxxxxxxxxxxxx>
"almost all programming can be viewed as an exercise in caching"
***********************************************************************
NOTICE: This e-mail transmission, and any documents, files or previous
e-mail messages attached to it, may contain confidential or privileged
information. If you are not the intended recipient, or a person
responsible for delivering it to the intended recipient, you are
hereby notified that any disclosure, copying, distribution or use of
any of the information contained in or attached to this message is
STRICTLY PROHIBITED. If you have received this transmission in error,
please immediately notify the sender and delete the e-mail and attached
documents. Thank you.
***********************************************************************



Relevant Pages

  • Re: number of days between two dates
    ... > i have some trouble making an exercise for school:( ... > i need an algoritm that calculate the exactly number of days between ...
    (comp.lang.asm.x86)
  • number of days between two dates
    ... i have some trouble making an exercise for school:( ... i need an algoritm that calculate the exactly number of days between ...
    (comp.lang.asm.x86)