Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

for nieto

Posted on 2000-04-30
3
Medium Priority
?
185 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 20 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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++.
Suggested Courses

916 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