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 624891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:14:59+00:00 2026-05-13T19:14:59+00:00

How would I put together a PHP5 function that would find the current calendar

  • 0

How would I put together a PHP5 function that would find the current calendar week and return the dates of each day in the week as an array, starting on Monday? For example, if the function were run today (Thu Feb 25 2010), the function would return an array like:

[0] => Mon Feb 22 2010<br />
[1] => Tue Feb 23 2010<br />
[2] => Wed Feb 24 2010<br />
[3] => Thu Feb 25 2010<br />
[4] => Fri Feb 26 2010<br />
[5] => Sat Feb 27 2010<br />
[6] => Sun Feb 28 2010<br />

It doesn’t matter what format the dates are stored as in the array, as I assume that’d be very easy to change. Also, it’d be nice to optionally be able to supply a date as a parameter and get the calendar week of that date instead of the current one.

Thanks!

  • 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-05-13T19:15:00+00:00Added an answer on May 13, 2026 at 7:15 pm

    I suppose a solution would be to start by getting the timestamp that correspond to last monday, using strtotime :

    $timestampFirstDay = strtotime('last monday');
    

    But if you try with today (thursday), with something like this :

    $timestampFirstDay = strtotime('last thursday');
    var_dump(date('Y-m-d', $timestampFirstDay));
    

    you’ll get :

    string '2010-02-18' (length=10)
    

    i.e. last week… For strtotime, “last” means “the one before today”.

    Which mean you’ll have to test if today is “last monday” as returned by strtotime plus one week — and, if so, add one week…

    Here’s a possible (there are probably smarter ideas) solution :

    $timestampFirstDay = strtotime('last monday');
    if (date('Y-m-d', $timestampFirstDay) == date('Y-m-d', time() - 7*24*3600)) {
        // we are that day... => add one week
        $timestampFirstDay += 7 * 24 * 3600;
    }
    

    And now that we have the timestamp of “last monday”, we can write a simple for loop that loops 7 times, adding 1 day each time, like this :

    $currentDay = $timestampFirstDay;
    for ($i = 0 ; $i < 7 ; $i++) {
        echo date('Y-m-d', $currentDay) . '<br />';
        $currentDay += 24 * 3600;
    }
    

    Which will give us this kind of output :

    2010-02-22
    2010-02-23
    2010-02-24
    2010-02-25
    2010-02-26
    2010-02-27
    2010-02-28
    

    Now, up to you to :

    • Modify that for loop so it stores the dates in an array
    • Decide which format you want to use for the date function

    Have fun 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I would like to put a string into a byte array, but the string
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
Have a quick project I need to put together for windows that can have
I have a utility that I put together that uses the .NET Framework to
For testing purposes I'm planning to put together a little app that will listen
Ok, this is possibly borderline-subjective, but I wonder where one would put a simple
I know java and would normally put in getter/setter methods. I am interested in
I would like to put a link to a webpage in an alert dialog
I would like to know how to put all of my ListView rows into
Let's put Heisenberg aside for a brief moment. How would I go about to,

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.