Solved

for nieto

Posted on 2000-04-30
3
179 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

773 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