Solved

From "01/01/1900" to "monday". How???

Posted on 1999-01-15
5
207 Views
Last Modified: 2010-04-16
Given a date, how can I work out the day of the week?
Since I'm in England and we do dates as dd/mm/yy, I want to enter a date, for example 15/04/1976 and the function to return a value for Thursday (which was the day of the week for 15/04/1976 if I remember). The way I'm thinking would probably work but it would be so long that it would just be dumb to use. No grace or finesse. Come on, astound me.
I think this could be hard so there's 200 points riding on it!
0
Comment
Question by:wierd_dave
5 Comments
 

Expert Comment

by:ahTri
ID: 1182312
I'm not really sure to attemp to take the 200 points u offer but i'm thinking of setting a fix date for example today (Saturday, 16/1/1999) calculate the number of days from today to the date u want to query, devide that number to 7, the remain of the division can be calculate to make the Date.

If u think this way work I will send u the set of objects to calculate the number of days from one day to another. Sorry for your 200 points if u not satisfy with this answer
0
 
LVL 84

Expert Comment

by:ozo
ID: 1182313
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
 

Author Comment

by:wierd_dave
ID: 1182314
Sorry ahTri, that was fairly much the way I was thinking. I was going to work out the number of days from 01/01/1900 and use the remainder as you said to get the date.
Rejection seems so negative, but i've tried ozos' method and it is far batter than I would have some up with.
If ozo wants to submit an answer, they can have the 200 points.

Thanks to both of you.
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1182315
I have written a program to work out what day of the week it is on any specific date, in that there is a function that tells you the day number from 1900...

Well?  Interested?
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 1182316
char *weekday[]={"Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","Monday"};
 dd=15;
 mm=4;
 yy=1976;
if( mm < 3 ){ mm += 12; yy -= 1; }
JulianDayNumber = 1721088 + dd + (mm-2)*367/12 + yy*365 + yy/4 - yy/100 + yy/400;
printf("%s\n",weeday[JulianDayNumber%7])
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 101
Setting nameservers after res_init fails doing res_query 2 98
C++ question 3 65
Arduino EDI - Programming language 3 95
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 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