Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Mate de Vita

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

  1. #1
    Andreas85b is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default 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:
    Need help calculating the day in a week of any date-test.jpg

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,928
    Rep Power
    19

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Andreas85b is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

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

    Quote Originally Posted by Tolls View Post
    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. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,928
    Rep Power
    19

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Mate de Vita is offline Member
    Join Date
    Mar 2012
    Posts
    63
    Rep Power
    0

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

    Quote Originally Posted by Andreas85b View Post
    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;
    Tolls likes this.

  6. #6
    Andreas85b is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

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

    Quote Originally Posted by Mate de Vita View Post
    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. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,928
    Rep Power
    19

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

    Look up modulus operator.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Calculate the day of the week for a particular date
    By Nghasemi in forum New To Java
    Replies: 6
    Last Post: 03-07-2011, 04:10 AM
  2. Date calculation based on month, week, day selection
    By narvava in forum Advanced Java
    Replies: 1
    Last Post: 01-23-2011, 10:23 PM
  3. Second week into Java - errors
    By hayden06f4i in forum New To Java
    Replies: 9
    Last Post: 11-03-2010, 05:01 PM
  4. Day of the Week Calculator
    By scheng12 in forum New To Java
    Replies: 0
    Last Post: 09-08-2009, 03:59 PM
  5. Date of first day, given the week in the year and the year...
    By Lee.J.Baxter in forum Advanced Java
    Replies: 1
    Last Post: 08-26-2009, 08:48 AM

Posting Permissions

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