0

I'm very new to PHP and Im trying to find the right syntax to get the difference between two dates i got as strings. basically i have two dates;

  • An estimated completion date ($bcdate)
  • An actual completion date ($acdate)
  • A difference of two dates ($rfs)

I've tried using methods posted here and from php.net, but i cant seem to get the output for the difference ($rfs) out.

If i output the bc_date and actual_date alone, it works fine.

Heres what Iv been working with so far:

$bcdate = DateTime::createFromFormat('Ymd', get_field ('bc_date'));
$acdate = DateTime::createFromFormat('Ymd', get_field ('actual_date'));
$rfs  = $actual_date->diff($bc_date);

echo $acdate->format('j M Y');
echo $bcdate->format('j M Y');
echo $rfs->format('%R%a days');
vyywern
  • 37
  • 6

2 Answers2

0
                    $bcdate = DateTime::createFromFormat('Ymd', get_field ('bc_date'));
                    $acdate = DateTime::createFromFormat('Ymd', get_field ('actual_date'));
                    $rfs  = $acdate->diff($bcdate);
                            
                            echo $acdate->format('j M Y');
                            echo $bcdate->format('j M Y');
                            echo $rfs->format('%R%a days');

Thanks Gunaseelan!

vyywern
  • 37
  • 6
  • Go enable proper error_reporting _now_ – most likely PHP could have told you that already before you asked. – CBroe Feb 19 '15 at 12:00
-1

Have you tried using the DateDiff function? http://php.net/manual/en/function.date-diff.php

Dave
  • 967
  • 10
  • 23