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

1. Member
Join Date
Mar 2012
Posts
4
Rep Power
0

## 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:

2. Moderator
Join Date
Apr 2009
Posts
13,216
Rep Power
23

## 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.

3. Member
Join Date
Mar 2012
Posts
4
Rep Power
0

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

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>))??

4. Moderator
Join Date
Apr 2009
Posts
13,216
Rep Power
23

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

You'll want to look up String and Integer.

5. Member
Join Date
Mar 2012
Posts
65
Rep Power
0

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

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;

6. Member
Join Date
Mar 2012
Posts
4
Rep Power
0

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

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

7. Moderator
Join Date
Apr 2009
Posts
13,216
Rep Power
23

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

Look up modulus operator.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•