Solved

for nieto

Posted on 2000-04-30
3
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

617 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