It works fine on localhost, but when I upload it to my host online it shows this error:
syntax error, unexpected T_OBJECT_OPERATOR
How can I fix it? Do I have to define the DateTime function somewhere?
if ((new DateTime($date))->diff(new DateTime())->days > 10) {
echo 'test';
}
UPDATE:
$date = DateTime::createFromFormat('y-M-d l H:i a', $date);
if ($date->diff(new DateTime())->days > 10) {
Class member access on instantiation was added in PHP 5.4. You are probably running PHP 5.3 so you cannot use that syntax.
Change:
if ((new DateTime($date))->diff(new DateTime())->days > 10) {
to:
$date = new DateTime($date);
if ($date->diff(new DateTime())->days > 10) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With