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
Medium Priority
296 Views
Do you know an algorithm for the day of the week.
Ex.: What is the day of May 3rd, 1999
0
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

LVL 2

Accepted Solution

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;
}

References: ANSI Sec. 4.12.2.3
ISO Sec. 7.12.2.3

0

Author Comment

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

## Featured Post

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…
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.
###### Suggested Courses
Course of the Month7 days, 1 hour left to enroll