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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:23:14+00:00 2026-06-18T11:23:14+00:00

How to get all week start date and end date within a date range

  • 0

How to get all week start date and end date within a date range in PHP?

Week start = Sunday and week end = Saturday

Input

$start_date=’2013-02-01′
$end_date = ‘2013-02-28’

Output

start date=’2013-02-01′ End date =’2013-02-02′
start date=’2013-02-03′ End date =’2013-02-09′
start date=’2013-02-10′ End date =’2013-02-16′
start date=’2013-02-17′ End date =’2013-02-23′
start date=’2013-02-24′ End date =’2013-02-28′

Below code return the week start and end of the date given

 function getWeekDates($date)
{
    $week =  date('W', strtotime($date));
    $year =  date('Y', strtotime($date));
    $from = date("Y-m-d", strtotime("{$year}-W{$week}-1")); //Returns the date of monday in week
    $to = date("Y-m-d", strtotime("{$year}-W{$week}-7"));   //Returns the date of sunday in week
    echo "Start Date-->".$from."End Date -->".$to;//Output : Start Date-->2012-09-03 End Date-->2012-09-09
}

How can I get the result above?

  • 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-18T11:23:15+00:00Added an answer on June 18, 2026 at 11:23 am

    Try this one…

    $start_date = date('Y-m-d', strtotime('2013-02-01'));
    $end_date = date('Y-m-d', strtotime('2013-02-28'));
    $end_date1 = date('Y-m-d', strtotime('2013-02-28 + 6 days'));
    
    for($date = $start_date; $date <= $end_date1; $date = date('Y-m-d', strtotime($date. ' + 7 days')))
    {
        echo getWeekDates($date, $start_date, $end_date);
        echo "\n";
    }
    
    function getWeekDates($date, $start_date, $end_date)
    {
        $week =  date('W', strtotime($date));
        $year =  date('Y', strtotime($date));
        $from = date("Y-m-d", strtotime("{$year}-W{$week}+1")); //Returns the date of monday in week
        if($from < $start_date) $from = $start_date;
        $to = date("Y-m-d", strtotime("{$year}-W{$week}-6"));   //Returns the date of sunday in week
        if($to > $end_date) $to = $end_date;
        echo "Start Date-->".$from."End Date -->".$to;//Output : Start Date-->2012-09-03 End Date-->2012-09-09
    }  
    

    See Codepad.

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

Sidebar

Related Questions

I'm trying to get all appointments in outlook in week range, but reoccurring appointments
I have an Event table that specifies a date range with start_date and end_date
I am trying to get all Books from the server (local PHP script), that
Is it possible to get all 7 days for a given date using linq
I work with SQL Server 2005. I have a start and end date. Ex:
Last week i read about liquibase quick start and all the related tutorials but
Possible Duplicate: Get next/previous ISO week and year in PHP I am trying to
I have a bunch of NumericSteppers (start week, start year, end week, end year),
I'm trying to get the last Sunday between two week numbers - in order
I have a date range where a start date is 2 years prior 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.