Hi all,
I am trying to start date and end date which is running in my local machine but when I am trying to run online it is not working . here is the code:

echo " ONE";
    $pDate = date('Y-m-d');
    $curdate= (explode("-",$pDate));
    echo $curdate[1]."<br>";
    echo $curdate[2]."<br>";
    $date=$curdate[1];

    switch ($date)
       {
        case "01": echo "January!";
                   $month="Jan";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Mar 31");
                   $lowerBound = new DateTime("Jan 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Mar 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 31st  of  March.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $startdate. "<br>";
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                    break;
        case "02": echo "February!";
                   $month="Feb";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Mar 31");
                   $lowerBound = new DateTime("Jan 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Mar 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 31st  of  March.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "03": echo "March!";
                   $month="Mar";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Mar 31");
                   $lowerBound = new DateTime("Jan 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Mar 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 31st  of  March.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "04": echo "April!";
                   $month="April";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Jun 30");
                   $lowerBound = new DateTime("Apr 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("June 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 30th of  June.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+364 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                    break;
        case "05": echo "May!";
                  $month="May";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Jun 30");
                   $lowerBound = new DateTime("Apr 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("June 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 30th of  June.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+364 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "06": echo "June! ";
                   $month="Jun";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Jun 30");
                   $lowerBound = new DateTime("Apr 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("June 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 30th of  June.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+364 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "07": echo "July!";
                   $month="Jul";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Sep 30");
                   $lowerBound = new DateTime("Jul 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Sep 30");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 30th   of  September.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                    break;
        case "08": echo "August!";
                    $month="Aug";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Sep 30");
                   $lowerBound = new DateTime("Jul 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Sep 30");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 30th   of  September.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "09": echo "September!";
                    $month="Sep";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Sep 30");
                   $lowerBound = new DateTime("Jul 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Sep 30");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 30th   of  September.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "10": echo "October!";
                   $month="Oct";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Dec 31");
                   $lowerBound = new DateTime("Oct 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Dec 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 31st  of  December.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                    break;
        case "11": echo "November!";
                   $month="Nov";
                   $days=$curdate[2];

                   $upperBound = new DateTime("Dec 31");
                   $lowerBound = new DateTime("Oct 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Dec 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 31st  of  December.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;
                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        case "12": echo "December!";
                   $month="Dec";
                   $days=$curdate[2];
                   echo "Days ".$days;  
                   $upperBound = new DateTime("Dec 31");
                   $lowerBound = new DateTime("Oct 01");
                   $checkDate = new DateTime($month." ".$days);
                   if ($lowerBound < $upperBound) 
                     {
                     $between = $lowerBound < $checkDate && $checkDate < $upperBound;
                     echo "within range".$between;
                     $d1=strtotime("Dec 31");
                     $d2=ceil(($d1-time())/60/60/24);
                     echo "There are " . $d2 ." days until 31st  of  December.". "<br>";
                     $NewDate=Date('Y-m-d', strtotime("+$d2 days"));
                     $startdate = $NewDate;

                     $enddate = date('Y-m-d', strtotime($startdate) + strtotime("+365 day", 0));
                     echo $pDate. "<br>";
                     echo $enddate. "<br>";
                     } 
                else 
                     {
                      $between = $checkDate < $upperBound || $checkDate > $lowerBound;
                      echo "not within range".$between;
                     }
                      var_dump($between);
                   break;
        default:
             echo "Your favorite date is out of range!";
       } 

it is not working

What's not working?

Am not sure what you are trying to achieve (tldr), but it looks like there is a much shorter solution.

WOW, quite a chunk of code! I agree with pritaeas. What exactly are you trying to do?

I am trying to start date and end date??

Hi pritaeas and jeffey,

$upperBound = new DateTime("Mar 31");
$lowerBound = new DateTime("Jan 01");

This syntax is working fine in local machine but when uploaded online it is not working . Is it possible to work any other way ?

What I am trying to do is :

If current date between Ist Jan to 31st March for One year then start date will be Ist April ,2014 and End date will be 31st March,2015.

If current date between Ist April to 30th June for One year then start date will be Ist July ,2014 and End date will be 30th June,2015.

If current date between Ist July to 30th September for One year then start date will be Ist October ,2014 and End date will be 30th December,2015.

If current date between Ist October to 30th December for One year then start date will be Ist January ,2015 and End date will be 3st March,2015.

Similary for two years ,year will be 2016 and three years 2017 .

Thanks,

Subrata

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.