Date conversion algorithm - Help needed

S

Se'noj

Hi all,
In a program I am writing, I need to convert a date stored as an
integer number of days into a standard gregorian format, with day zero
being 1/1/1800. Can anyone help me with this?

Bryan Jones
NightDaemon Enterprises
nightdaemon.co.nr
 
V

Victor Bazarov

Se'noj said:
In a program I am writing, I need to convert a date stored as an
integer number of days into a standard gregorian format, with day zero
being 1/1/1800. Can anyone help me with this?

So, what's really stopping you? Every year is 365 except the leap ones,
which are 366. Now, the number of days in your date, where is it counted
from?
 
E

E. Robert Tisdale

Se'noj said:
In a program I am writing,
I need to convert a date stored as an integer number of days
into a standard gregorian format,
with day zero being 1/1/1800.
Can anyone help me with this?
cal 1 1800
January 1800
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

I used Google

http://www.google.com/

to search for

+"C++" +"Gregorian date"

and I found lots of stuff.
 
M

Micha

Victor said:
So, what's really stopping you? Every year is 365 except the leap ones,
which are 366. Now, the number of days in your date, where is it counted
from?

only nearly :) every 100 hundred years the leap day is dropped, but there
are also exception (every 400 years I think), so 2000 was a leap year
 
V

Victor Bazarov

Micha said:
Victor Bazarov wrote:




only nearly :) every 100 hundred years the leap day is dropped, but there
are also exception (every 400 years I think), so 2000 was a leap year

Perhaps you misunderstand what "leap" means, Micha? It means the year
has an extra day, thus making a leap, a jump, to catch up with the true
solar year. Did you misread what I wrote? I didn't say "every fourth
year has an extra day", did I? So, nothing "nearly" about what I wrote.
 
M

Mike Wahler

Micha said:
only nearly :) every 100 hundred years the leap day is dropped, but there
are also exception (every 400 years I think), so 2000 was a leap year

Yes, there are several rules for determining which years
are leap years, but this doesn't change the fact Victor
cited: leap years contain 366 days.

You can google for the calculation rules.


-Mike
 
M

Micha

Victor said:
Perhaps you misunderstand what "leap" means, Micha? It means the year
has an extra day, thus making a leap, a jump, to catch up with the true
solar year. Did you misread what I wrote? I didn't say "every fourth
year has an extra day", did I? So, nothing "nearly" about what I wrote.

indeed my german is a little bit better than my english - although I know
what "leap" means (and I think the original poster also knows that there
are leap years)

but what I ment was, that even if I know that there are leap years, it isn't
obviously easy to catch all exceptions; so why invent such a boring
algorithm myself, if there is surely somebody out there who has already
done it with a nice little piece of code?
 
V

Victor Bazarov

Micha said:
[...]
but what I ment was, that even if I know that there are leap years, it isn't
obviously easy to catch all exceptions; so why invent such a boring
algorithm myself, if there is surely somebody out there who has already
done it with a nice little piece of code?

Let me get this straight. When you said (and I quote):

"only nearly :) every 100 hundred years the leap day is dropped,
but there are also exception (every 400 years I think), so 2000
was a leap year"

you actually meant "don't reinvent the wheel"? Fascinating!
 
O

osmium

Victor Bazarov said:
[...]
but what I ment was, that even if I know that there are leap years, it
isn't
obviously easy to catch all exceptions; so why invent such a boring
algorithm myself, if there is surely somebody out there who has already
done it with a nice little piece of code?

Let me get this straight. When you said (and I quote):

"only nearly :) every 100 hundred years the leap day is dropped,
but there are also exception (every 400 years I think), so 2000
was a leap year"

you actually meant "don't reinvent the wheel"? Fascinating!

LOL
 
M

Marcelo Pinto

Mike Wahler said:
Yes, there are several rules for determining which years
are leap years, but this doesn't change the fact Victor
cited: leap years contain 366 days.

You can google for the calculation rules.

int year;
//...
bool leap = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top