473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Date conversion algorithm - Help needed

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
Jul 22 '05 #1
9 1752
"Se'noj" <tl******@gmail.com> wrote...
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?
Jul 22 '05 #2
Se'noj wrote:
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.
Jul 22 '05 #3
Victor Bazarov wrote:
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


Jul 22 '05 #4
Micha wrote:
Victor Bazarov wrote:

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


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.
Jul 22 '05 #5

"Micha" <mi*****@fantasymail.de> wrote in message
news:cm**********@schlund.de...
Victor Bazarov wrote:
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


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
Jul 22 '05 #6
Victor Bazarov wrote:
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?


Jul 22 '05 #7
Micha wrote:
[...]
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!
Jul 22 '05 #8
"Victor Bazarov" wrote:
[...]
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
Jul 22 '05 #9
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<sh*****************@newsread3.news.pas.earth link.net>...
"Micha" <mi*****@fantasymail.de> wrote in message
news:cm**********@schlund.de...
Victor Bazarov wrote:
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


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);


-Mike


--
Marcelo Pinto
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Niall Porter | last post by:
Hi all, I'm building an ASP app on a Windows 2000/IIS machine which interfaces with our SQL Server 2000 database via OLE DB. Since we're based in the UK I want the users to be able to type in...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
3
by: Fraser Ross | last post by:
Does Boost have anything for doing a conversion of rate for a data sequence? E.g. sound sample data from 44100 per second to 50000. I don't expect the algorithm would be big. I standard algorithm...
26
by: David W. Fenton | last post by:
A client is panicking about their large Access application, which has been running smoothly with 100s of thousands of records for quite some time. They have a big project in the next year that will...
26
by: jshanman | last post by:
I am writing a timeline that uses Google Maps. I have a function that converts a date time to latitude coords. This function is used to draw the markers on the timeline. I need a reverse function...
10
by: melissa.nava | last post by:
Here is my code: ***** Public Property DOB() As Date Get Try DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear)
1
by: SSG | last post by:
How to insert date to the sql server database. I am getting input from the HTML form and store it to database using ASP. how to store date field, what datatype needed and what conversion...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
2
by: vinodtr | last post by:
Hi all, I have a date which is represented by the number of milliseconds since January 01, 1970. I need to change this back to DATE format. Is there any built in function in DB2 to do the needed...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.