1 Attachment(s)

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

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.

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

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.

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;

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

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

Look up modulus operator.