Solved

Day of the week

Posted on 1998-09-14
2
294 Views
Last Modified: 2010-04-15
Do you know an algorithm for the day of the week.
Ex.: What is the day of May 3rd, 1999
0
Comment
Question by:pchaloux
[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 Comments
 
LVL 2

Accepted Solution

by:
JYoungman earned 20 total points
ID: 1252709
See question 20.31 in http://www.eskimo.com/~scs/C-faq/top.html

uestion 20.31

How can I find the day of the week given the date?

Use mktime or localtime (see questions 13.13 and 13.14, but beware of DST adjustments if tm_hour is 0),
or Zeller's congruence (see the sci.math FAQ list), or this elegant code by Tomohiko Sakamoto:

dayofweek(y, m, d)      /* 0 = Sunday */
int y, m, d;            /* 1 <= m <= 12,  y > 1752 or so */
{
        static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
        y -= m < 3;
        return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

See also questions 13.14 and 20.32.

References: ANSI Sec. 4.12.2.3
ISO Sec. 7.12.2.3

0
 

Author Comment

by:pchaloux
ID: 1252710
Boy, that was fast.
Thank you
0

Featured Post

Independent Software Vendors: 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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

635 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