Solved

Day of the week

Posted on 1998-09-14
2
283 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
2 Comments
 
LVL 2

Accepted Solution

by:
JYoungman earned 20 total points
Comment Utility
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
Comment Utility
Boy, that was fast.
Thank you
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 for-loops 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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now