$now = new DateTime();
print_r($now);
print $now->date; // print the current date
BUT if print_r($now); is comment it show error ?
$now = new DateTime();
print $now->date; // Notice: Undefined property: DateTime::$date in
$now = new DateTime();
print_r($now);
print $now->date; // print the current date
BUT if print_r($now); is comment it show error ?
$now = new DateTime();
print $now->date; // Notice: Undefined property: DateTime::$date in
There is no such property in this class. Use format function instead:
echo $date->format('d.m.Y H:i:s');
This is a bug in PHP (I 'm not sure exactly which versions are affected).
Class DateTime does not have a date property, but calling print_r on it creates a "hidden" property that looks like it's there (it is displayed with print_r) but in reality is not (you cannot get its value).
Instead of this, use DateTime::format to get the date value in whatever format you want.
When you want to print the date using the DateTime object, use the following method:
$Date = new DateTime();
$Date->format('d/m/Y H:i');
The following page can help you format the output: