Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:12:45+00:00 2026-06-11T19:12:45+00:00

Given a Month and a weekday, I need to build a function that can

  • 0

Given a Month and a weekday, I need to build a function that can retrieve the day number of all Mondays, Tuesdays, Wednesdays, Thursdays and Fridays.

Let’s say I give the function this month, September 2012 and weekday number 1. The function should retrieve all the Mondays in September 2012 which are: 3, 10, 17 and 24

Please note that to me weekday number 1 is Monday, number 2 Tuesday, 3 is Wednesday, 4 Thursday and 5 Friday.

So far I’ve have done: getting the first day of the week given today’s date (I post the function below). But I don’t know how to follow from here in a simple way, I’ve been many hours on it and I suspect there’s a better way to do it. Can you please show me how?

  function getFirstDayOfWeek($date) {
    $getdate = getdate($date);

    // How many days ahead monday are we?
    switch ( $getdate['wday'] ) {
        case 0: // we are on sunday
            $days = 6;
            break;

        default: // any other day
            $days = $getdate['wday']-1;
            break;
    }

    $seconds = $days*24*60*60;
    $monday = date($getdate[0])-$seconds;

    return $monday;
}

Thanks a ton

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:12:46+00:00Added an answer on June 11, 2026 at 7:12 pm

    Not very smart, but would works for you:

    // sept. 2012
    $month = 9;
    
    // loop through month days
    for ($i = 1; $i <= 31; $i++) {
    
        // given month timestamp
        $timestamp = mktime(0, 0, 0, $month, $i, 2012);
    
        // to be sure we have not gone to the next month
        if (date("n", $timestamp) == $month) {
    
            // current day in the loop
            $day = date("N", $timestamp);
    
            // if this is between 1 to 5, weekdays, 1 = Monday, 5 = Friday
            if ($day == 1 OR $day <= 5) {
    
                // write it down now
                $days[$day][] = date("j", $timestamp);
            }
        }
    }
    
    // to see if it works :)
    print_r($days);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want find all Saturdays and Sundays in A given month. How can I
I need to get the last day of the month given as a date
I need to find all the weekend dates for a given month and a
I need to calculate the number of days for a given month in python.
How can I in rails calculate the number of weeks in a given month?
How would retrieve all customer's birthdays for a given month in SQL? What about
how can i get the whole month in day namesof given month/year? like :
I'm trying to find all Thursdays within a given Month using VBScript. Can anyone
I want to retrieve the last date of given month in iphone app. Can
Given a month and year, how do I know the dates for a day

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.