I'm sorry to ask such a basic question but this has been stumping me and I'm sure its got to be something simple.
All I want to be able to do is work out the number of days diference, as an interger between a field that an earlier part of my code retrieves, and the current date.
The code that gets my expiry date is $data100["ExpiryDate"]
, and I know that this works because when I echo, I get
2018-04-23
All I want is to figure out how to calculate the difference between $data100["ExpiryDate"] and now() in terms of an interger, e.g. 45, so that i can then see if it is within 3 months for a later section of the code.
I have tried a few articles on here, and phpmanual, but keep getting errors like:
Object of class DateInterval could not be converted to string
Sorry forgot to include code, this is one example I have tried...
$date1 = new DateTime($data100["ExpiryDate"]);
$date2 = new DateTime("now");
$interval=date_diff($date1,$date2);
Have also tried this:
> $interval = $datetime1->diff($datetime2); echo
> $interval->format('%R%a days');
But dont want this option as I just want the output as an interger.
Solved it using this, thanks.
$date1 = new DateTime($data100["ExpiryDate"]);
$date2 = new DateTime("now");
$diff = $date2->diff($date1)->format("%a");