Results 1 to 2 of 2

Math Help - Work out generic formula to deduce number of days to add to date to hit nearest Fri

  1. #1
    Newbie
    Joined
    Mar 2011
    Posts
    1

    Work out generic formula to deduce number of days to add to date to hit nearest Fri

    Hi,
    I am trying to work out a generic formula to deduce the number of days to add to any date to in turn deduce the date of the next Friday closest to that date, using the week day number.
    So the given constants are:
    Target week day number: 6 (Friday)
    Number of Days in week: 7

    Date | Day | Week Day Number | Number of Days to Add | Target Week Day Number
    5-Mar-11 |Saturday|7|6|6
    6-Mar-11 |Sunday|1 |5|6
    7-Mar-11 |Monday|2|4|6
    8-Mar-11 |Tuesday|3|3|6
    9-Mar-11 |Wednesday|4|2|6
    10-Mar-11 |Thursday|5|1|6
    11-Mar-11 |Friday|6|0|6



    So for example for the date 6-Mar-2011 which is a Sunday the following formula will work:
    => Target Week Day - WeekDay Number
    => 6 - 1
    => 5
    So if I add 5 days to 6-Mar-2011 I will hit the target Friday date of 11-Mar-2011

    but this formula does not work for the first date listed in above table 5-Mar-2011.

    So I was hoping to get advice on a single generic formula to achieve this and the approach to take on coming up with this formula
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member Aryth's Avatar
    Joined
    Feb 2007
    From
    USA
    Posts
    652
    Thanks
    2
    Awards
    1
    Quote Originally Posted by bazzer View Post
    Hi,
    I am trying to work out a generic formula to deduce the number of days to add to any date to in turn deduce the date of the next Friday closest to that date, using the week day number.
    So the given constants are:
    Target week day number: 6 (Friday)
    Number of Days in week: 7

    Date | Day | Week Day Number | Number of Days to Add | Target Week Day Number
    5-Mar-11 |Saturday|7|6|6
    6-Mar-11 |Sunday|1 |5|6
    7-Mar-11 |Monday|2|4|6
    8-Mar-11 |Tuesday|3|3|6
    9-Mar-11 |Wednesday|4|2|6
    10-Mar-11 |Thursday|5|1|6
    11-Mar-11 |Friday|6|0|6



    So for example for the date 6-Mar-2011 which is a Sunday the following formula will work:
    => Target Week Day - WeekDay Number
    => 6 - 1
    => 5
    So if I add 5 days to 6-Mar-2011 I will hit the target Friday date of 11-Mar-2011

    but this formula does not work for the first date listed in above table 5-Mar-2011.

    So I was hoping to get advice on a single generic formula to achieve this and the approach to take on coming up with this formula
    Count your days like this and your formula will work:

    Saturday = 1
    Sunday = 2
    Monday = 3
    Tuesday = 4
    Wednesday = 5
    Thursday = 6
    Friday = 7

    Please keep in mind this is only for Friday. If you pick another target day, that day will be number 7, let's say the target was Tuesday, then you'd have to count your days like this:

    Wednesday = 1
    Thursday = 2
    Friday = 3
    Saturday = 4
    Sunday = 5
    Monday = 6
    Tuesday = 7

    The formula is right, you just HAVE to change the order of the days.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Work hours rounded to the nearest quarter
    Posted in the Algebra Forum
    Replies: 8
    Last Post: July 14th 2011, 09:37 AM
  2. Replies: 8
    Last Post: February 11th 2011, 09:59 AM
  3. Deriving a generic formula:
    Posted in the Algebra Forum
    Replies: 1
    Last Post: June 21st 2010, 07:27 PM
  4. How to make generic filenames work in matlab?
    Posted in the Math Software Forum
    Replies: 1
    Last Post: June 9th 2010, 08:25 PM
  5. Deduce from Mobius inversion formula
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: April 15th 2008, 04:40 PM

Search Tags


/mathhelpforum @mathhelpforum