-5

I am a bit new to PHP is there a way to display a month in succession?

the sample is my first date is July 01, 2018

the output should be

July 01, 2018
Aug 01, 2018
Sept 01, 2018 ..

and so on until to the date I declare

Update: here is my code

$propd = "SELECT * FROM tbl_sample WHERE Person_ID = ".$Person_ID;
$prop_counter = $conn->query($propd);

while($pcount_Row = $prop_counter->fetch_assoc()) {
    $Acceptance_Date = $pcount_Row["Accpt_Date"];
}

/////////////////////////////

$NAcceptance_Date = strtotime($Acceptance_Date);
$nMonth = strtotime($Acceptance_Date);
$Start_Date = date('M d,Y', $NAcceptance_Date);

$x=1;
$Month_Counter=1;
$Monthly[$x] = $Start_Date;
//echo $Monthly[$x];
$x++;

$JDate=strtotime("June 01, 2018");
$JuneDate = date("M d,Y", $JDate);


while ($Start_Date != $JuneDate)
{
$Start_Date = date("M d, Y", strtotime("+1 month", $nMonth));
$nMonth= strtotime($Start_Date);
echo $Start_Date . "-" . $JuneDate . "<br>";
}

where

$Acceptance_Date = July 01, 2009
$JuneDate = June 01, 2018

but my won't stop at June 01, 2018

Ozarraga_AB
  • 939
  • 5
  • 15
  • 24
  • put your code which you have tried. – Gufran Hasan Aug 29 '18 at 09:06
  • @GufranHasan i don't have one, don't know how to code it – Ozarraga_AB Aug 29 '18 at 09:08
  • 6
    At least an attempt? – pr1nc3 Aug 29 '18 at 09:08
  • Loop and http://php.net/manual/en/class.dateinterval.php – HorusKol Aug 29 '18 at 09:11
  • 3
    Possible duplicate of [get a list of months that have passed upto todays date - PHP](https://stackoverflow.com/questions/12071635/get-a-list-of-months-that-have-passed-upto-todays-date-php) – pr1nc3 Aug 29 '18 at 09:14
  • 1/ Create a var with your first date, 2/ Create a loop with a end condition (date max?), 3/ Each time you loop : display the current date then add one month untill end condition is false – Mickaël Leger Aug 29 '18 at 09:14
  • You can use this answer and simply change the month counts within the for loop. https://stackoverflow.com/a/10829455/4034148 – wbdlc Aug 29 '18 at 09:16
  • Possible duplicate of [Displaying the list of months using mktime for the year 2012](https://stackoverflow.com/questions/10829424/displaying-the-list-of-months-using-mktime-for-the-year-2012) – wbdlc Aug 29 '18 at 09:16

2 Answers2

0

Something similar to this should work for you, though you'll need to look up strtotime(), date() and for loops:

$time = strtotime("July 01, 2018");

$nextMonth = date("m d, Y", strtotime("+1 month", $time)); //Loop this til you find the date you want to stop at

But then you need to loop through until the date you want, then break out of the loop.

This is not a complete copy and paste answer, it requires you to do some work on it.

Adam
  • 1,294
  • 11
  • 24
  • This does not answer to the question. You just get the next month not the list of the next months – pr1nc3 Aug 29 '18 at 09:13
  • You need to loop through as stated. It's not a full answer, it's an answer that makes you do some work yourself. – Adam Aug 29 '18 at 09:20
0
<?php
/* On met la date au format mysql. Enfoiré d'anglophones. LE SYSTEME METRIQUE ET NOS NORMES VAINCRONS */
    function date_to_mysql($album_date){
        $album_date = explode("-",$album_date);
        $date = intval($album_date[0]).'-'.intval($album_date[1]).'-'.intval($album_date[2]); /** add +1 to middle for month+1, in my case it's alreay formated */
        unset($album_date);
        return $date;
    }
?>

here's a way to do that in PHP Wanna know the amout of months that passed?

Substract total by current month.

Want the month/day_name? PHP does it for you with date functions too or make an associative array and swap values

Dice
  • 236
  • 1
  • 8
  • You can get the current month using date('m'), and you can loop starting from intval of day/year/month to max amout of month/day/year – Dice Aug 29 '18 at 12:39