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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:13:23+00:00 2026-05-25T10:13:23+00:00

I saw this code on a forum : $begin = new DateTime( $start_date );

  • 0

I saw this code on a forum:

 $begin = new DateTime( $start_date );
    $end = new DateTime(date("Y-m-d",strtotime("+1 day", strtotime($end_date))));
    while($begin < $end) {
        $period[] = $begin->format('Y-m-d');
        $begin->modify('+1 day');
    }

I want to do exactly what the OP was asking i.e. create a date interval of 1 day without using DateInterval class as I am not using PHP 5.3 (I’m using 5.2)

However when I try to use the $period array I get an error:

Undefined variable: period

This is my code:

    $start = new DateTime("09-09-2011");
    $end   = new DateTime("24-09-2011");

         while($start < $end) {

        $period[] = $start->format('Y-m-d');
        $start->modify('+1 day');

        }

print_r($period) //error - undefined variable

Why does it not work – is it to do with putting a datetime object in a while loop?

  • 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-25T10:13:24+00:00Added an answer on May 25, 2026 at 10:13 am

    so define it easily

    $period = array();
    

    however, this will never go to that while loop = this code is not useful

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

Sidebar

Related Questions

I saw this C++ code on a forum which minimizes all open windows #define
I saw this on the codeigniter forum Considering the below code UPDATE a INNER
const static int foo = 42; I saw this in some code here on
I recently saw a bit of code that looked like this (with sock being
I saw this the other day (scroll all the way down to see some
I am a PHP beginner and saw on the forum this PHP expression: My
The question came up when I saw this code: private static volatile ConcurrentHashMap<String, String>
I saw this code. I removed some of the irrelevant code to make it
I saw this line in the jQuery.form.js source code: g && $.event.trigger(ajaxComplete, [xhr, s]);
I saw this code in Ajax in Action book and there are two things

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.