Reputation: 5856
I have the following code 2 count days between 2 dates:
$start = '2013-04-02';
$end = '';
if($end){
$now = $end;
}else{
$now = time();
}
$your_date = strtotime($start);
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));
This works fine and calculates the correct amount of days.
When i enter a end date like this:
$start = '2013-04-02';
$end = '2013-09-11';
if($end){
$now = $end;
}else{
$now = time();
}
$your_date = strtotime($start);
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));
I get a result of -15797.
Does the above seem ok? Or am i doing something wrong?
Upvotes: 0
Views: 139
Reputation: 1360
Try this::
$start = new DateTime('2013-04-02');
$end = new DateTime('2013-09-11');
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($start, $interval, $end);
$count=count($period);
echo $count;
Upvotes: 1
Reputation: 1371
shoud be:
$start = '2013-04-02';
$end = '2013-09-11';
if($end){
$now = strtotime($end);
}else{
$now = time();
}
$your_date = strtotime($start);
$datediff = $now - $your_date;
echo floor($datediff/(60*60*24));
Upvotes: 0