Raja Manickam
Raja Manickam

Reputation: 1903

how to display the date between the from and to range of date in php

How do I display a range of dates from 28-10-2014 to 01-11-2014?

28-10-2014
29-10-2014
30-10-2014
31-10-2014
01-11-2014

Upvotes: 0

Views: 143

Answers (2)

Gowri
Gowri

Reputation: 1856

Try this:

<?php 
$begin = new DateTime('28-10-2014');
$end = new DateTime('01-11-2014');

$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);

foreach($daterange as $date){
    echo $date->format("m-d-Y");
}

?>

Upvotes: 2

Pupil
Pupil

Reputation: 23958

<?php
$date = "10-28-2014";
$date1 = str_replace('-', '/', $date);
$iterations = 4;
for ($i=0 ; $i<=  $iterations ; $i++) {
  $tomorrow = date('d-m-Y',strtotime($date1 . "+$i days"));
  echo '<br/>'.$tomorrow;
}
?>

Hope this works.

Upvotes: 1

Related Questions