Solved

for nieto

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 133
How to convert MFC::CString to UTF8 wchar_t* 10 371
Safe conversion? 4 75
max float value 3 59
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…
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…
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++.

740 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