Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Day of the week

Posted on 1998-09-14
2
Medium Priority
?
296 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 80 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

705 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