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

  • SEARCH
  • Home
  • 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 7846097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:27:54+00:00 2026-06-02T17:27:54+00:00

I created the following array manually (bottom), I wish to create it programmatically using

  • 0

I created the following array manually (bottom), I wish to create it programmatically using only two strings which can be easily exploded (explode()).

$min_date = '2012-03-01 00:00:00';
$max_date = '2012-04-25 00:00:00';

I’ve already explode() the strings as well as found out how many months are between the two dates

    $min_date = explode('-',$min_date);
    $min_date['year'] = intval($min_date[0]);
    $min_date['month'] = intval($min_date[1]);
    $min_date['day'] = intval($min_date[2]);

    $max_date = explode('-',$max_date);
    $max_date['year'] = intval($max_date[0]);
    $max_date['month'] = intval($max_date[1]);
    $max_date['day'] = intval($max_date[2]);

$months_between = ($max_date['month'] - $min_date['month']) + 12 * ($max_date['year'] - $min_date['year']);

which returns 1

cal_days_in_month() function seems useful too, I just don’t know how…

$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year)

Here is the array I created manually!

$periods = array(
  '0' => array(
    'month'=>'march',
    'week'=>'1',
    'days'=>'4',
    'readable'=>' Thurs Mar, 01, 2012 - Sun Mar, 04, 2012',
    'created_at_min'=>'2012-03-01 00:00:00',
    'created_at_max'=>'2012-03-04 24:00:00'
  ),
  '1' => array(
    'month'=>'march',
    'week'=>'2',
    'days'=>'7',
    'readable'=>' Mon Mar, 05, 2012 - Sun Mar, 11, 2012',
    'created_at_min'=>'2012-03-05 00:00:00',
    'created_at_max'=>'2012-03-11 24:00:00'
  ),
  '2' => array(
    'month'=>'march',
    'week'=>'3',
    'days'=>'7',
    'readable'=>' Mon Mar, 12, 2012 - Sun Mar, 18, 2012',
    'created_at_min'=>'2012-03-12 00:00:00',
    'created_at_max'=>'2012-03-18 24:00:00'
  ),
  '3' => array(
    'month'=>'march',
    'week'=>'4',
    'days'=>'7',
    'readable'=>' Mon Mar, 19, 2012 - Sun Mar, 25, 2012',
    'created_at_min'=>'2012-03-19 00:00:00',
    'created_at_max'=>'2012-03-25 24:00:00'
  ),
  '4' => array(
    'month'=>'march',
    'week'=>'5',
    'days'=>'6',
    'readable'=>' Mon Mar, 26, 2012 - Sun Mar, 31, 2012',
    'created_at_min'=>'2012-03-26 00:00:00',
    'created_at_max'=>'2012-03-31 24:00:00'
  ),
  '5' => array(
    'month'=>'april',
    'week'=>'1',
    'days'=>'1',
    'readable'=>' Sun Apr, 1, 2012',
    'created_at_min'=>'2012-04-01 00:00:00',
    'created_at_max'=>'2012-04-01 24:00:00'
  ),
  '6' => array(
    'month'=>'april',
    'week'=>'2',
    'days'=>'7',
    'readable'=>' Mon Apr, 2, 2012 - Sun Apr, 8, 2012',
    'created_at_min'=>'2012-04-01 00:00:00',
    'created_at_max'=>'2012-04-08 24:00:00'
  ),
  '7' => array(
    'month'=>'april',
    'week'=>'3',
    'days'=>'7',
    'readable'=>' Mon Apr, 9, 2012 - Sun Apr, 15, 2012',
    'created_at_min'=>'2012-04-09 00:00:00',
    'created_at_max'=>'2012-04-15 24:00:00'
  ),
  '8' => array(
    'month'=>'april',
    'week'=>'4',
    'days'=>'7',
    'readable'=>' Mon Apr, 16, 2012 - Sun Apr, 22, 2012',
    'created_at_min'=>'2012-04-16 00:00:00',
    'created_at_max'=>'2012-04-22 24:00:00'
  ),
  '9' => array(
    'month'=>'april',
    'week'=>'5',
    'days'=>'3',
    'readable'=>' Mon Apr, 23, 2012 - Wed Apr, 25, 2012',
    'created_at_min'=>'2012-04-16 00:00:00',
    'created_at_max'=>'2012-04-25 00:00:00' // note last day timestamp needs to be 00:00:00
  ),
);

Is their anything that PHP offers that can be of extreme help before I dive into this?

$weeks = array(
  'may' = array(1,2,3,4,5),
  'april' = array(1,2,3,4,5),
);
  • 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-02T17:27:56+00:00Added an answer on June 2, 2026 at 5:27 pm
    $min_date = new DateTime('2012-03-01 00:00:00');
    $max_date = new DateTime('2012-04-25 00:00:00');
    $numOfWeeks = ceil($min_date->diff($max_date)->days / 7.0);
    
    $baseDate = $min_date->getTimestamp();
    $startOfWeek = 'Mon';
    for ($i = 0; $i <= $numOfWeeks + 1; $i++)
    {
        $weekRangeStart = date('D M, d, Y', $baseDate);
        if (date('M', strtotime("Next Sunday", $baseDate)) == date('M', $baseDate))
        {
            $weekRangeEnd = date('D M, d, Y', strtotime("Next Sunday", $baseDate));
            $nextDateObject = new DateTime(date('r', strtotime('Next Monday', $baseDate)));
        }
        else
        {
            $weekRangeEnd = date('D M, d, Y', strtotime("last day of this month", $baseDate));
            $nextDateObject = new DateTime(date('r', strtotime("last day of this month", $baseDate)));
        }
    
        $baseDateObject = new DateTime(date('r', $baseDate));
    
        $daysInWeek = $baseDateObject->diff($nextDateObject)->days;
    
        $periods[] = array('month' => date('F', $baseDate), 'days' => $daysInWeek, 
                    'readable' => $weekRangeStart . ' - ' . $weekRangeEnd);
    
        if (date('D', $baseDate) != $startOfWeek)
            $baseDate = strtotime("Next Monday", $baseDate);
        else
            $baseDate = strtotime("+1 week", $baseDate);
    }
    
    var_dump($periods);
    

    Do something like this. You’ll get a an array like:

        array
      0 => 
        array
          'month' => string 'March' (length=5)
          'days' => int 4
          'readable' => string 'Thu Mar, 01, 2012 - Sun Mar, 04, 2012' (length=37)
      1 => 
        array
          'month' => string 'March' (length=5)
          'days' => int 7
          'readable' => string 'Mon Mar, 05, 2012 - Sun Mar, 11, 2012' (length=37)
      2 => 
        array
          'month' => string 'March' (length=5)
          'days' => int 7
          'readable' => string 'Mon Mar, 12, 2012 - Sun Mar, 18, 2012' (length=37)
      3 => 
        array
          'month' => string 'March' (length=5)
          'days' => int 7
          'readable' => string 'Mon Mar, 19, 2012 - Sun Mar, 25, 2012' (length=37)
      4 => 
        array
          'month' => string 'March' (length=5)
          'days' => int 5
          'readable' => string 'Mon Mar, 26, 2012 - Sat Mar, 31, 2012' (length=37)
      5 => 
        array
          'month' => string 'April' (length=5)
          'days' => int 7
          'readable' => string 'Mon Apr, 02, 2012 - Sun Apr, 08, 2012' (length=37)
      6 => 
        array
          'month' => string 'April' (length=5)
          'days' => int 7
          'readable' => string 'Mon Apr, 09, 2012 - Sun Apr, 15, 2012' (length=37)
      7 => 
        array
          'month' => string 'April' (length=5)
          'days' => int 7
          'readable' => string 'Mon Apr, 16, 2012 - Sun Apr, 22, 2012' (length=37)
      8 => 
        array
          'month' => string 'April' (length=5)
          'days' => int 7
          'readable' => string 'Mon Apr, 23, 2012 - Sun Apr, 29, 2012' (length=37)
      9 => 
        array
          'month' => string 'April' (length=5)
          'days' => int 0
          'readable' => string 'Mon Apr, 30, 2012 - Mon Apr, 30, 2012' (length=37)
    

    EDIT: Code updated so that weeks don’t span months.

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

Sidebar

Related Questions

I have the following three arrays and need to create a new two-dimensional array
I created the following 2D array in Javascript // Create basic linear array var
I am using the following array to add an object that was previously created
I am trying to dynamically create a Bitmap Image using byte array using following
I created the following interface: <?php interface Action { public function execute(\requests\Request $request, array
I am trying to iterate a multidimension array created with the following line To
I use the following code try to create an array of string vectors, I
I am trying to create an associative array that collects the following (existing on
I'm really struggling to create a valid multidimensional JavaScript array with the following basic
I have created following thing in android using android compatibility support package Basically i

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.