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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:24:27+00:00 2026-05-23T22:24:27+00:00

I am using following codes to display start and end dates of current month.

  • 0

I am using following codes to display start and end dates of current month.

function firstOfMonth() {
return date("m/d/Y", strtotime(date('m').'/01/'.date('Y').' 00:00:00'));
}

function lastOfMonth() {
return date("m/d/Y", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00'))));
}

$date_start = firstOfMonth();
$date_end  = lastOfMonth();
echo $date_start;
echo $date_end;

Question: How to get start and end dates of all months in a range of date given

For Eg:

function daterange($startdate,$enddate)
{
...
...
...
}

Expected result be array of start and end dates of each month between date range of $startdate and $enddate.

Help me how to do this….

  • 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-23T22:24:28+00:00Added an answer on May 23, 2026 at 10:24 pm
    <?php
    //Function to return out start and end dates of all months in a date range given
    
    function rent_range($start_date, $end_date)
    {
        $start_date = date("m/d/Y", strtotime($start_date));
        $end_date   = date("m/d/Y", strtotime($end_date));
        $start = strtotime($start_date);
        $end = strtotime($end_date);
    
        $month = $start;
        $months[] = date('Y-m', $start);
        while($month < $end) {
          $month = strtotime("+1 month", $month);
          $months[] = date('Y-m', $month);
        }
    
        foreach($months as $mon)
        {
            $mon_arr = explode( "-", $mon);
            $y = $mon_arr[0];
            $m = $mon_arr[1];
            $start_dates_arr[] = date("m/d/Y", strtotime($m.'/01/'.$y.' 00:00:00'));
            $end_dates_arr[] = date("m/d/Y", strtotime('-1 minute', strtotime('+1 month',strtotime($m.'/01/'.$y.' 00:00:00'))));
        }
    
        //to remove first month in start date and add our start date as first date
        array_shift($start_dates_arr);
        array_pop($start_dates_arr);
        array_unshift($start_dates_arr, $start_date);
    
        //To remove last month in end date and add our end date as last date
        array_pop($end_dates_arr);
        array_pop($end_dates_arr);
        array_push($end_dates_arr, $end_date);
    
        $result['start_dates'] = $start_dates_arr;
        $result['end_dates'] = $end_dates_arr;
        return $result;
    }
    
    $start_date = '2011-07-29';
    $end_date = '2012-03-31';
    $res = rent_range($start_date, $end_date);
    echo "<pre>";
    print_r($res);
    echo "</pre>";
    ?>
    

    My Above Function will give the month range display of dates within a given range.
    This function would be useful for monthly rent calculation as indian tradition.

    It may help some one else….

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

Sidebar

Related Questions

I want to display the last March month. I am using the following code,
I am using the following code to display an index for a TableView. My
Using the following code, I am able to display up to 10 images. What
I am using the following code to try and display in a time in
I have the following code to display an image in imagebox using EmgucV: Capture
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
i am trying to display the results of the following javascript function in a
I am using the following code to display a video file in the android
I'm using the following code to display an advertisement in a flash game. It
I am using following code in WPF to display image in webcam usingEmguCv library

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.