473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1782
"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*****@fantas ymail.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******@mkwah ler.net> wrote in message news:<sh******* **********@news read3.news.pas. earthlink.net>. ..
"Micha" <mi*****@fantas ymail.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
3166
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 dates in UK date format to input into the database. In Enterprise Manager on the SQL Server I can manually enter a record into a table and just type in a UK date (MM/DD/YYYY e.g. 25/12/2004) and it accepts it happily.
8
3032
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 Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
3
1503
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 would be useful of course. Fraser.
26
3830
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 lead to a lot of use of the database and the adding of quite a lot of new data (though I can't conceive of them adding more than than 10s of thousands of records, which won't change the current performance profile at all). If there is a SQL...
26
2728
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 to convert a latitude coord back to an accurate date time. Then I could detect the day/hour in the viewport when the timeline is zoomed in or out, or if it is moved. I cannot use the javascript date functions because this timeline will...
10
1677
by: melissa.nava | last post by:
Here is my code: ***** Public Property DOB() As Date Get Try DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear)
1
10402
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 needed. Thanx & Regards, SSG
44
10236
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
24245
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 conversion ? In Oracle i was able to do the conversion by the following statement. select to_char(to_date('01/01/1970','mm/dd/yyyy'),'mm/dd/yyyy') + milliseconds/86400000) from dual; Note: In the above sql statement, milliseconds is the no:...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.