Solved

for nieto

Posted on 2000-04-30
3
180 Views
Last Modified: 2010-04-02
can u explain the code u post for the calendar?
how that equation works?
can u explain the number u used?
0
Comment
Question by:danieldaniel_2000
  • 2
3 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2764718
Is this for me?

If so, I'm not sure what it refers to.
0
 

Author Comment

by:danieldaniel_2000
ID: 2764731
here it is:
can u tell me how u get those number for the equation?


From: nietod
 Date: Monday, February 08 1999 - 04:10PM PST  
For example,
// The date in dd/mm/yyyy.
int dd=1;
int mm=1;
int yy=1900;

int jdn;
char *weekday[]={"Tuesday",
"Wednesday",
"THursday",
"Friday",
"Saturday",
"Sunday",
"Monday"};

if (mm < 3)
{
   mm += 12;
   yy -= 1;
}
jdn = dd+1720996+(mm+1)*306/10+yy*365 + yy/4 - yy/100 + yy/400;

printf("%s\n",weeday[jdn%7]);
 
0
 
LVL 22

Accepted Solution

by:
nietod earned 5 total points
ID: 2764755
That is not something I invented.  It is a relatively well known formula.  It calculates an integer serial date.  That is, for any date it calculates a unique integer value that is one more than the value produced by the previous date.  This can be used to calculate the number of days between two dates.

 The numbers were chosen so that when the numbers entered are rounded to an integer they yield the right result    For example,
306/10 is the average number of days in a month, when you do mm+1*306/10 you get the number of days into the year at the start of the specifid month  Add dd to that (which is the first item) and you get the number of days into the year etc.   You add on yy*365 to get the number of  days at the start of the year from year 0 (there was no actual year 0, but...) The three figures at the end are to correct for leap years.  i.e. dividing the year by 4 gives the number of leap years since year 0, which gives the number of extra leap days that have been accumlated by the specified date.  (Or would have accumulated, if leap years were performed since year "0", they didn't start untile the 1600's so the foruma isn't accurate before then.)  - yy/100 corrects for the fact that a year that is divisible by 100 is not a leap year, even though it is divible by 4.  and so on.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question