1

I'm creating a datetime object with:

$datetime = date_create_from_format('Y-m-d\TH:i:sP', $string);

Which gives an object with properties date, timezone_type, and timezone. But I can't access any of these properties:

return $datetime->date;

This returns null. What am I doing wrong?

Edit:

var_dump($datetime) gives:

object(DateTime)#807 (3) {
  ["date"]=>
  string(19) "2015-04-14 13:28:06"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}
babbaggeii
  • 7,577
  • 20
  • 64
  • 118

1 Answers1

1

There is Bug issue regarding this in php. You cant access it directly. Use format method. Try with -

$datetime->format('Y-m-d H:i:s')
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87