# Need help calculating the day in a week of any date

Printable View

• 03-14-2012, 10:39 AM
Andreas85b
Need help calculating the day in a week of any date
Hello
I need help calculating the day of the week when entering a specific date.
For example 15th January 2009 --- The output must be ---> Day number 5 (which is Thursday).
I must use this function: Day = (D + (26 *(M+1))/10 + Y + Y/4 + C/4 - 2*C) % 7;

Basicley for now im stuck on calculating Century's and Years so that when the input is 2009
then Century = 20 ( C = 20 )
and Year = 09 ( Y = 9 )
I have to separate those somehow from one whole number to 2 separate numbers
** The month 1 and 2 are calculated as months 13 and 14 OF THE PREVIOUS YEAR
** I must only use simple Methods

This is what I did for now:
Attachment 3243
• 03-14-2012, 11:22 AM
Tolls
Re: Need help calculating the day in a week of any date
Read the year in as a String and then substring it for the parts you want, then parse them to ints.
• 03-14-2012, 11:35 AM
Andreas85b
Re: Need help calculating the day in a week of any date
Quote:

Originally Posted by Tolls
Read the year in as a String and then substring it for the parts you want, then parse them to ints.

What do you mean by "substring"ing? I know there is an operator that calculates the entire amount of characters from left to right, but i cant remember what it looks like :(
In addition how can I create a method that only calculates the numbers after the first 2? or up to the first to ((x=(<3>))??
• 03-14-2012, 11:49 AM
Tolls
Re: Need help calculating the day in a week of any date
The API is your friend.
You'll want to look up String and Integer.
• 03-14-2012, 12:22 PM
Mate de Vita
Re: Need help calculating the day in a week of any date
Quote:

Originally Posted by Andreas85b
Basicley for now im stuck on calculating Century's and Years so that when the input is 2009
then Century = 20 ( C = 20 )
and Year = 09 ( Y = 9 )
I have to separate those somehow from one whole number to 2 separate numbers

Couldn't you just do
Century = Year/100;
Year %= 100;
• 03-15-2012, 08:45 AM
Andreas85b
Re: Need help calculating the day in a week of any date
Quote:

Originally Posted by Mate de Vita
Couldn't you just do
Century = Year/100;
Year %= 100;

Thank you for the useful answer.
But can you please explain to me Step by Step what the Year %=100 does?
for example Year 2000 and Year 2012
Thanks
• 03-15-2012, 10:50 AM
Tolls
Re: Need help calculating the day in a week of any date
Look up modulus operator.