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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:39:52+00:00 2026-06-18T09:39:52+00:00

I want to get the start date and end date of two weeks within

  • 0

I want to get the start date and end date of two weeks within a date range in PHP.

Week start = Sunday and week end = Saturday

ie)for example if date range is

$start = ‘2013-01-01’ and
$end =’2013-02-28′

Required Result

Start Date–>2013-01-01 End Date –>2013-01-12
Start Date–>2013-01-13 End Date –>2013-01-26
Start Date–>2013-01-27 End Date –>2013-02-09
Start Date–>2013-02-10 End Date –>2013-02-23
Start Date–>2013-02-24 End Date –>2013-02-28

Code

  <?php
$st = '2013-01-01';
$et ='2013-02-28';
$start_date = date('Y-m-d', strtotime($st));
$end_date = date('Y-m-d', strtotime($et));
$end_date1 = date('Y-m-d', strtotime($et. '+ 6 days'));

$weekfrom = array();
$weekto = array();

for($date = $start_date; $date <= $end_date1; $date = date('Y-m-d', strtotime($date. ' + 14 days')))
{

    $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;       

     }
    if($from < $to)
    {
    array_push($weekfrom,$from);
    array_push($weekto,$to);
    }

}
$n = count($weekfrom);

for($i = 0;$i<$n;$i++)
{
  echo "Start Date-->".$weekfrom[$i];
  echo " End Date -->".$weekto[$i]."\n";
}


?>

Current Result

Start Date–>2013-01-01 End Date –>2013-01-05
Start Date–>2013-01-13 End Date –>2013-01-19
Start Date–>2013-01-27 End Date –>2013-02-02
Start Date–>2013-02-10 End Date –>2013-02-16
Start Date–>2013-02-24 End Date –>2013-02-28

DEMO

In the current result the start date is correct.But the issue is within the end date. Help me to find the issue

  • 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-18T09:39:53+00:00Added an answer on June 18, 2026 at 9:39 am

    Just change to this one…

    $to = date("Y-m-d", strtotime("{$year}-W{$week}-6 + 1 week"));
    

    See Codepad

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

Sidebar

Related Questions

I want to get one record before start date and end date DtpFrom means
I want to get week Start Date of a week. I am able to
I want to get the start and end date of the previous calender month.
I am using Jquery Date pickers to get Start and End Dates for an
Example I have: range = start.to_date..(end.to_date + 1.day) end and start are dates. How
I want to get two particular dates by using current date, let me explain
I want to get start with DayPilot control I do not use SQLite and
I want to get the thread's start address with NtQueryInformationThread , but I need
I want to get ready for HTML 5 and start playing around with it.
I work with SQL Server 2005. I have a start and end date. Ex:

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.