0

I have tried to get this date diff function working all night now, its fine until i feed it my two variables.

What am I doing wrong ?

<h2>Date diff attempt</h2>
    <?php
    $z = $row->account_add_date;
    $y = $row->start_amount;

    $date1=date_create($z);
    $date2=date_create($y);
    $diff=date_diff($date1,$date2);
    echo $diff->format('%d days');
    ?>

When I run it I get

Severity: Warning

Message: date_diff() expects parameter 2 to be DateTime, boolean given
Beep
  • 2,737
  • 7
  • 36
  • 85

2 Answers2

0

Try this one.

$date1 = $row->account_add_date;
$date2 =$row->start_amount;    
$date1 = new DateTime($date1);
$date2 = new DateTime($date2);

echo $date1->diff($date2)->format("%d days, %h hours and %i minuts");
Gopalakrishnan
  • 957
  • 8
  • 19
0

It is working properly, I thing there is some problem in your $row->account_add_date and $row->start_amount

<h2>Date diff attempt</h2>
<?php
$z = "2013-03-15";
$y = "2013-03-31";

$date1=date_create($z);
$date2=date_create($y);
$diff=date_diff($date1,$date2);
echo $diff->format('%d days');
?>
SAUMYA
  • 1,508
  • 1
  • 13
  • 20